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

PlayerAdded Script not working in online?

Asked by
iLegitus 130
8 years ago
--[iLegimate]--

game.Players.PlayerAdded:connect(function(player)
    if player.Name == "Player" then
        player:WaitForChild("StarterGear")
    local sc = game.ReplicatedStorage["HARD_DRIVE"].ScriptStorage.MapChoserApproval:Clone()
    local sc2 = game.ReplicatedStorage["HARD_DRIVE"].ScriptStorage.MapChoserApproval2:Clone()
        sc2.Parent = player.StarterGear
        sc.Parent = player.Backpack
        else
        return nil
    end
end)

So this works perfectly in studio..But for some reason when i test it in an actual game it wont work?

(MapChoserApproval 1 & 2 are scripts which clone a gui into the player's playergui) (My intention is to clone a gui into my playergui (Basically like a gear in startergear,But in PlayerGui)

0
It's because of the if then statement on line 4. Unless someone named Player enters, your script will not run. M39a9am3R 3210 — 8y
0
Um,Wait it has PlayerAdded event to it,So when a player joins it checks if the player's name is ilegimate,If it isnt it doesnt run iLegitus 130 — 8y
0
" if player.Name == "Player" then" That is 100% what line 4 says... M39a9am3R 3210 — 8y
0
You don't need to check anything, the PlayerAdded event will only fire if an actual player connects to the server. Just remove the if statement and you'll be good to go. BlackJPI 2658 — 8y
0
And the return nil ScripterGame 145 — 8y

1 answer

Log in to vote
0
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
8 years ago

As the others have explained, line 4 is what prevents your code from executing. The reason it works in Studio, is because the testing server makes you the "Player" player. There's no need to check if it's an actual Player, because the PlayerAdded event only fires if it's a legitimate player. I also reduced some lines by moving stuff together.

game.Players.PlayerAdded:connect(function(player)
    player:WaitForChild("StarterGear")
    game.ReplicatedStorage["HARD_DRIVE"].ScriptStorage.MapChoserApproval:clone().Parent = player.Backpack
    game.ReplicatedStorage["HARD_DRIVE"].ScriptStorage.MapChoserApproval2:clone().Parent = player.StarterGear
end)
Ad

Answer this question