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

Why wont my admin only tool get into my backpack?

local allowed = {"world_kiIIer", "kleppolek"}

  

game.Players.PlayerAdded:Connect(function(player)

for i, v in pairs(allowed) do

if game.Players.LocalPlayer.Name == v then

script.kickhammer.Parent = game.Players.LocalPlayer:WaitForChild("Backpack")

end

end

end)

the kickhammer works perfectly but it wont get into the backpack, why? this is a local script located in starterpack and i get no output, nothing happens when i test the game trying to make it so only me world_kiIIer and my friend kleppolek get the tool when we join

2 comments

0

We need more desc, like : script location, script type, any output messages

0

explained

2 answers

✓ Accepted answer

The problem is that the local script is executed after the player is added, therefor, PlayerAdded will not fire for you.

Create identical logic using a server-script: in most cases, server-scripts will execute before player(s) can join the game. You will most importantly want to make use of the player parameter in the PlayerAdded event because server-side scripts may not use the LocalPlayer property.

local allowed = {"world_kiIIer", "kleppolek"}

game.Players.PlayerAdded:Connect(function(player)
    for i, v in pairs(allowed) do
	    if player.Name == v then
		    script.kickhammer.Parent = player:WaitForChild("Backpack") --you may want to clone 'kickhammer' before you set its parent, else this chunk of code will only find 'script.kickhammer' once
	    end
    end
end)

i tried to put the hammer into another script that also has the allowed function, here is that script its a server script inside serverscriptservice

local allowed = {"world_kiIIer", "kleppolek", "Femme_Devil"}

  

game.Players.PlayerAdded:Connect(function(player)

for i, v in pairs(allowed) do

if player.Name == v then

script.KickGui:Clone().Parent = player:WaitForChild("PlayerGui")

script.kickhammer:Clone().Parent = player:WaitForChild("Backpack")

end

end

end)

the gui clones but not the hammer, why

2 comments

0

You clone 'kickhammer' into the player's backpack before the character loads. When the character loads, the Backpack gets deleted. Wait for the player's character to load before the clone to tool into the player's character. If my first answer solved your problem, marking it as solved would be etiquette!

0

i will test and i will mark as answered if it works

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