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

Detecting a player when they join?

Asked by 5 years ago

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)
0
Did you put it in server script service? turquoise_monkeyman 32 — 5y
0
You should be using the event CharacterAdded User#5423 17 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

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!

Ad
Log in to vote
0
Answered by
Norbunny 555 Moderation Voter
5 years ago

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)
0
he'll have to wait for descendants of the character Gey4Jesus69 2705 — 5y

Answer this question