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

PlayerAdded not working?

Asked by 10 years ago

EDIT 2

game.Players.ChildAdded:connect(function(newPlayer)
    newPlayer.Character.Humanoid.WalkSpeed = 0
    newPlayer.Character.Humanoid.MaxHealth = math.huge
    newPlayer.Character.Humanoid.Health = 9e9
    script.Parent.TextTransparency = 0.9
    wait(0.1)
    script.Parent.TextTransparency = 0.8
    wait(0.1)
    script.Parent.TextTransparency = 0.7
    wait(0.1)
    script.Parent.TextTransparency = 0.6
    wait(0.1)
    script.Parent.TextTransparency = 0.5
    wait(0.1)
    script.Parent.TextTransparency = 0.4
    wait(0.1)
    script.Parent.TextTransparency = 0.3
    wait(0.1)
    script.Parent.TextTransparency = 0.2
    wait(0.1)
    script.Parent.TextTransparency = 0.1
    wait(0.1)
    script.Parent.TextTransparency = 0
    wait(3)
    script.Parent.TextTransparency = 0.1
    wait(0.1)
    script.Parent.TextTransparency = 0.2
    wait(0.1)
    script.Parent.TextTransparency = 0.3
    wait(0.1)
    script.Parent.TextTransparency = 0.4
    wait(0.1)
    script.Parent.TextTransparency = 0.5
    wait(0.1)
    script.Parent.TextTransparency = 0.6
    wait(0.1)
    script.Parent.TextTransparency = 0.7
    wait(0.1)
    script.Parent.TextTransparency = 0.8
    wait(0.1)
    script.Parent.TextTransparency = 0.9
    wait(0.1)
    script.Parent.TextTransparency = 1
    script.Parent.Text = "Afraid of The Dark"
    wait(3)
    game.Workspace.Sound:Play()
    script.Parent.BackgroundTransparency = 0.9
    wait(0.1)
    script.Parent.BackgroundTransparency = 0.8
    wait(0.1)
    script.Parent.BackgroundTransparency = 0.7
    wait(0.1)
    script.Parent.BackgroundTransparency = 0.6
    wait(0.1)
    script.Parent.BackgroundTransparency = 0.5
    wait(0.1)
    script.Parent.BackgroundTransparency = 0.4
    wait(0.1)
    script.Parent.BackgroundTransparency = 0.3
    wait(0.1)
    script.Parent.BackgroundTransparency = 0.2
    wait(0.1)
    script.Parent.BackgroundTransparency = 0.1
    wait(0.1)
    script.Parent.BackgroundTransparency = 0
    wait(5)
    script.Parent.BackgroundTransparency = 0.1
    wait(0.1)
    script.Parent.BackgroundTransparency = 0.2
    wait(0.1)
    script.Parent.BackgroundTransparency = 0.3
    wait(0.1)
    script.Parent.BackgroundTransparency = 0.4
    wait(0.1)
    script.Parent.BackgroundTransparency = 0.5
    wait(0.1)
    script.Parent.BackgroundTransparency = 0.6
    wait(0.1)
    script.Parent.BackgroundTransparency = 0.7
    wait(0.1)
    script.Parent.BackgroundTransparency = 0.8
    wait(0.1)
    script.Parent.BackgroundTransparency = 0.9
    wait(0.1)
    script.Parent.BackgroundTransparency = 1
    newPlayer.Character.Humanoid.WalkSpeed = 16
    newPlayer.Character.Humanoid.MaxHealth = 100
    newPlayer.Character.Humanoid.Health = 100
end)



Please tell me why this won't work.

3 answers

Log in to vote
3
Answered by
Merely 2122 Moderation Voter Community Moderator
10 years ago

PlayerAdded doesn't fire for LocalScripts. You'll have to use game.Players.ChildAdded instead.

0
It doesn't work. Grenaderade 525 — 10y
0
Another issue - your code makes the assumption that the Character exists as soon as the player is added. You need to connect to the Player.CharacterAdded event. Merely 2122 — 10y
Ad
Log in to vote
1
Answered by
Defaultio 160
10 years ago

Assuming this is a server side script, you can only call game.Players.LocalPlayer from a LocalScript (hence local Player). Instead, you would want

game.Players.ChildAdded:connect(function(newPlayer)
    newPlayer.Character.Humanoid.WalkSpeed = 0
    newPlayer.Character.Humanoid.MaxHealth = math.huge
    newPlayer.Character.Humanoid.Health = 9e9

However, if you've got a LocalScript here and it's in something like StarterGui, a copy of this script will be given to each player that joins the game. So you know that this player has joined the game when the script starts running. You can just forget the connections and jump straight into business.

Also, I really suggest that you look into for loops! All that transparency code works, but it can really be condensed.

Log in to vote
-1
Answered by 10 years ago

game.Players.PlayerAdded

Answer this question