I'm trying to clone a knife gear into a player's backpack using values for an inventory feature. Simple as that. This is testing things like this so that's why it seems so forced to happen:
game.Players.PlayerAdded:Connect(function(plr) local KnifeValue = Instance.new("StringValue", plr) wait() KnifeValue.Value = game.ServerStorage.DefaultKnife.Name if KnifeValue.Value == game.ServerStorage.DefaultKnife.Name then game.ServerStorage.DefaultKnife:Clone().Parent = plr.Backpack end end)
When I do that it doesn't show up in my backpack nor in the explorer. If I change plr.Backpack to simply plr, it does show up in the explorer. Is there anything extra I have to add?
game.Players.PlayerAdded:Connect(function(plr) local KnifeValue = Instance.new("StringValue") KnifeValue.Parent = plr KnifeValue.Value = game.ServerStorage:WaitForChild("DefaultKnife").Name game.ServerStorage.DefaultKnife:Clone().Parent = plr.Backpack end)
This is the correct way to do it, also remember it has to be a server script on serverscriptservice, this will work ONCE every player joins, if you also want to do it every time a player respawns, do this:
game.Players.PlayerAdded:Connect(function(plr) plr.CharacterAdded:Connect(function(char) local KnifeValue = Instance.new("StringValue") KnifeValue.Parent = plr KnifeValue.Value = game.ServerStorage:WaitForChild("DefaultKnife").Name game.ServerStorage.DefaultKnife:Clone().Parent = plr.Backpack end) end)
Hope I helped!