如果玩家死亡,但有同一工具的克隆,而不是所有克隆只保存1只有1个,我遇到问题,我该如何解决此问题?
我的最终成就是要在玩家死亡时要保存的重复工具
,如果玩家拥有三个“枪1”,那么死亡而不是在库存中仍然有三枪1,他们只有一个枪1。
这就是我目前有
local Inventory = {}
local function Spawned(Char)
local Plr = game.Players:GetPlayerFromCharacter(Char)
for i,v in pairs(Inventory[Plr]) do
if Plr['Backpack']:findFirstChild(v.Name) then
Plr['Backpack'][v.Name]:Destroy()
end
v.Parent = Plr['Backpack']
end
Inventory[Plr] = {}
Char:WaitForChild('Humanoid').Died:connect(function()
for i,v in pairs({Plr['Backpack'], Char}) do
for ii,vv in pairs(v:GetChildren()) do
if vv:IsA('Tool') then
table.insert(Inventory[Plr], vv:Clone())
vv:Destroy()
end
end
end
end)
end
game.Players.PlayerAdded:connect(function(Plr)
Inventory[Plr] = {}
local Char = Plr.Character or Plr.CharacterAdded:wait()
Spawned(Char)
Plr.CharacterAdded:connect(Spawned)
end)
My end achievement is wanting the duplicate tools to save when the player dies
For example, if the player owns three "Gun 1s" then dies instead of still having three Gun 1s in their inventory they will only have one Gun 1.
This is what I currently got
local Inventory = {}
local function Spawned(Char)
local Plr = game.Players:GetPlayerFromCharacter(Char)
for i,v in pairs(Inventory[Plr]) do
if Plr['Backpack']:findFirstChild(v.Name) then
Plr['Backpack'][v.Name]:Destroy()
end
v.Parent = Plr['Backpack']
end
Inventory[Plr] = {}
Char:WaitForChild('Humanoid').Died:connect(function()
for i,v in pairs({Plr['Backpack'], Char}) do
for ii,vv in pairs(v:GetChildren()) do
if vv:IsA('Tool') then
table.insert(Inventory[Plr], vv:Clone())
vv:Destroy()
end
end
end
end)
end
game.Players.PlayerAdded:connect(function(Plr)
Inventory[Plr] = {}
local Char = Plr.Character or Plr.CharacterAdded:wait()
Spawned(Char)
Plr.CharacterAdded:connect(Spawned)
end)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在这里摧毁克隆。
You are destroying the clones here.