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

I have an error on this script and I dont know how to fix it, how would I?

So i tried to make a script where it would give me a keycard when I spawn, but it gives me an error what did i do wrong?

local players = {"CelticFury600"}
local gear = game.ServerStorage.Keycard

game.Players.PlayerAdded:connect(function(plr)
    plr.CharacterAdded:connect(function(chr)
        for i = 1, #players do
            if players[i] == plr.Name then
                gear:Clone().Parent = plr:WaitForChild("Backpack")
            end
        end
    end)

1 comment

0

Can you please post the error in the output? That can help me come up with a solution.

2 answers

✓ Accepted answer

You forgot to add an end) for the playerAdded event. Since you haven't included it, that means that there's no end) for the event.

1 comment

0

thanks

Alright, I tested the script, and I found the issue.

ISSUE:

You were missing an "end)" at the end of the script, ending the "PlayerAdded" function.

FIXED SCRIPT:

local players = {"CelticFury600"} --Change this to any name you want. If you want it to be any player, use "Game.Players:GetChildren()".
local gear = game.ServerStorage.Keycard
 
game.Players.PlayerAdded:connect(function(plr)
    plr.CharacterAdded:connect(function(chr)
        for i = 1, #players do
            if players[i] == plr.Name then
                gear:Clone().Parent = plr:WaitForChild("Backpack")
            end
        end
    end)
end)

Hope this helped!

-Maxis_s

1 comment

0

thanks

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