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

Why does my script not clone the tool??

Asked by 9 years ago

This script is meant to clone a tool into a player with a specified userId. But it doesn't work. No output errors too!

newPlayer = game.Players.LocalPlayer
if newPlayer.userId == 32441993 or newPlayer.userId == 36491121 or newPlayer.userId == 37983438 then
    a = game.Lighting:WaitForChild("Admin")
    if a ~= nil then
        backpack = newPlayer:WaitForChild("Backpack")
        if backpack ~= nil then
            a:Clone()
            a.Parent = backpack
        end
    end
end
0
You could check the player's name instead of the userId, and use a playeradded event. Operation_Meme 890 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

When you use WaitForChild, there is no point in checking to see if it returns nil -- it won't return until it has a non-nil value.

To debug, use print statements to see if the script is even running and what it executes:

print("begin")
newPlayer = game.Players.LocalPlayer
print("player", newPlayer, "id:", newplayer.userId)
if newPlayer.userId == 32441993 or newPlayer.userId == 36491121 or newPlayer.userId == 37983438 then
print("user is admin")
    a = game.Lighting:WaitForChild("Admin")
print("game.Lighting.Admin returned", a)
        backpack = newPlayer:WaitForChild("Backpack")
print("backpack:", backpack)
            a:Clone()
            a.Parent = backpack
print("gave admin to player")
        end
    end
end
print("done")

One error I see is that you call "a:Clone()" but then you don't use the clone. This error wouldn't cause a syntax error, it'd just move the Admin from the lighting to the newest player, meaning that the script would appear to work the first time, but not the 2nd. You could do a:Clone().Parent = backpack instead.

Ad

Answer this question