Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Player's Backpack doesn't receive tools from script, what's the problem?

Asked by 5 years ago

The following code uses a "for" loop to clone game.ServerStorage.Tools.Donut (a tool) and give it to a player who joined the game:

game.Players.PlayerAdded:Connect(function(client)
    for i = 1, 3 do 
        repeat wait()
        until client:FindFirstChild("Backpack") 
        local donut = game.ServerStorage.tools.Donut:Clone()
        donut.Parent = client.Backpack
    end
end)

This didn't work, so I tried putting wait() once the client joins

game.Players.PlayerAdded:Connect(function(client)
    wait(5)
    for i = 1, 3 do 
        repeat wait()
        until client:FindFirstChild("Backpack") 
        local donut = game.ServerStorage.tools.Donut:Clone()
        donut.Parent = client.Backpack
    end
end)

This worked, though. I'm not sure why it's like this. Is it because the player's Character needs to be loaded for them to recieve the tools?

1 answer

Log in to vote
1
Answered by
EthanFins 104
5 years ago

I hope this helped

game.Players.PlayerAdded:Connect(function(client)
        wait(5)
        for i = 1, 3 do
            -- under this will wait until the character is loaded to receive tools      
            repeat until client.Character:FindFirstChild("HumanoidRootPart")
            until client:FindFirstChild("Backpack")
            local donut = game.ServerStorage.tools.Donut:Clone()
            donut.Parent = client.Backpack
       end
end)
Ad

Answer this question