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

PlayerAdded not working?

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

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

2 comments

0

It doesn't work.

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.

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.

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