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

Why wont my admin only tool get into my backpack?

Asked by 4 years ago
Edited 4 years ago

Please provide more explanation in your question. If you explain exactly what you are trying to accomplish, it will be much easier to answer your question correctly.
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

0
We need more desc, like : script location, script type, any output messages User#24403 69 — 4y
0
explained Gameplayer365247v2 1055 — 4y

2 answers

Log in to vote
1
Answered by
pidgey 548 Moderation Voter
4 years ago

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)
Ad
Log in to vote
0
Answered by 4 years ago

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

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! pidgey 548 — 4y
0
i will test and i will mark as answered if it works Gameplayer365247v2 1055 — 4y

Answer this question