Just as an example, in piggy, when you click a new item, the old item in your backpack disappears. The same thing is what I want to replicate in my game.
So i have an item (a key) that contains a click detector and the following Script:
local tool = game.ServerStorage.tools.redkeytool
local klone = tool:clone()
script.Parent.ClickDetector.MouseClick:Connect(function(plr)
if klone.Parent ~= plr.Backpack then
klone.Parent = plr.Backpack
plr.Backpack.keyid.Value = "red"
else
end
if plr.Backpack.keyid.Value == "blue" then
plr.Backpack.bluekeytool:Destroy()
end
if plr.Backpack.keyid.Value == "green" then
plr.Backpack.greenkeytool:Destroy()
end
if plr.Backpack.keyid.Value == "silver" then
plr.Backpack.silverkeytool:Destroy()
end
if plr.Backpack.keyid.Value == "purple" then
plr.Backpack.purplekeytool:Destroy()
end
if plr.Backpack.keyid.Value == "wood" then
plr.Backpack.woodtool:Destroy()
end
if plr.Backpack.keyid.Value == "wirecutters" then
plr.Backpack.wirecutterstool:Destroy()
end
if plr.Backpack.keyid.Value == "orange" then
plr.Backpack.orangekeytool:Destroy()
end
if plr.Backpack.keyid.Value == "gold" then
plr.Backpack.golddkeytool:Destroy()
end
end)
(keyid is a StringValue in the players backpack so the game knows what the player is holding)
It returns with the error saying keyid is not a valid member of Backpack.
Although I made a localscript that clones "keyid" into the players backpack:
print("Hello world!")
local keyid = game.Workspace.keyid
local keyid2 = keyid:Clone()
keyid2.Parent = game.Players.LocalPlayer:WaitForChild("Backpack")
UPDATE:
Okay so I got it to work using FindFirstChild(), but now if i were to take a key (key 1), then replace it with another key (key 2), and then go back to key 1 to replace it with key 2, it says:
the current parent of redkey is locked, currect parent: NULL, new parent: backpack
Not sure what this means

1 comment
It's a local script, meaning it's not there for the server. Things made in client don't replicate to server