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
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