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

Detecting a player when they join?

I want to have it so when a player joins I change there head transparency to 1 and then make the humanoid a PlatformStand except this doesn't work... I don't get any failed output but I added the print("hi") just to see if it was the character portion that isn't working... I am really stumped... I am semi-new to scripting so it is probably something obvious...

function playerAdded(player)
	wait(2)
	if player.Name == "Player" then
		local character = player.Character
		character.Head.Transparency = 1
		character.humanoid.PlatformStand = true
		print("hi")
	end
end

game.Players.PlayerAdded:connect(playerAdded)

2 comments

0

Did you put it in server script service?

0

You should be using the event CharacterAdded

2 answers

✓ Accepted answer

You should be using CharacterAdded for this.

game.Players.PlayerAdded:Connect(function(player)
   player.CharacterAdded:Connect(function(char)
      local head = char:WaitForChild("Head")
      local hum = char:WaitForChild("Humanoid")
      head.Transparency = 1
      humanoid.PlatformStand = true
   end)
end)

If it doesn't work, try adding a wait immediately after the CharacterAdded. Sometimes I have to wait a little bit because it doesn't run.

##Accept and upvote if this helps!

Like stated before, you might want to use .CharacterAdded instead, so that the script runs everytime the player's character is loaded.

local players = game:GetService('Players')


players.PlayerAdded:Connect(function(plr) -- once a player joins
	if(plr.Name == "yourPlayerName") then -- checks if it's the player you're looking for
		plr.CharacterAdded:Connect(function(char) -- connects to whenever the char loads
			-- you code goes here
			-- instead of player.Character you can just then do char.Head
		end)
	end
end)

1 comment

0

he'll have to wait for descendants of the character

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