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:

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

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

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

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

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

Answer this question