When a player joins I want to equip a tool to their backpack.
So far I have tried this code that does not seem to work:
game.Players.PlayerAdded:Connect(function(plr)
local tools = {"Sword"}
for i, toolName in ipairs(tools) do
local tool = game.ServerStorage.Tools[toolName]
local newToolObj = tool:Clone()
newToolObj:WaitForChild("Handle")
newToolObj.Parent = plr.Backpack or plr:WaitForChild("Backpack")
end
end)
Is there any way to get this to work?
remove the “i” in “ipairs”
or just remove the script and put all the tools in StarterPack instead
Just put the tools in StarterPack to clone them to player.
EDIT: You don’t need any scripts for it. Just put the tool in StarterPack, and you’re good to go.
1 Like
local tools = {"Sword"}
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function()
for _,v in ipairs(tools) do
local tool = game.ServerStorage.Tools:FindFirstChild(v)
if tool then tool:Clone().Parent = plr.Backpack end
end
end)
end)
You can do something like this.
1 Like
Thank you! I forgot to wait for the character to be added before cloning the tool.
1 Like