Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does my script not clone the tool??

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

1 comment

0

You could check the player's name instead of the userId, and use a playeradded event.

1 answer

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.