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

How Do You Connect To the Players body through the PlayerAdded Function? Thanks!!

Asked by 6 years ago

Im trying to connect to the players body but I'm using a player added function and i haven't used roblox studio in a very long time so if u can help it'll be much appreciated

So... So Far I got this

game.Player.PlayerAdded:connect(function(plr)
...
end

thanks !?!?!

2 answers

Log in to vote
0
Answered by
DanzLua 2879 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

Well to get the character from a player we can do Player.Character so,

game.Player.PlayerAdded:connect(function(plr)
    local char = plr.Character or plr.CharacterAdded:wait()
    -- OR plr.CharacterAdded:wait() because sometimes the character
    -- might not be there
end)

Furthermore we can use the characteradded event of player to do something every time they spawn

game.Player.PlayerAdded:connect(function(plr)
    plr.CharacterAdded:connect(function(char)
        print(char.Name)
    end)
end)

Also you were missing a ) in end, end) , in your code.

Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Use this.

game.Player.PlayerAdded:connect(function(plr)
    local character = workspace:WaitForChild(plr.Name)
end)

Also, you are lucky that I decided not to moderate your question.

0
Why is he lucky? He attempted to do it so it doesn't make it incorrect to ask for help. DanzLua 2879 — 6y
0
He didnt look at the properties of the player. hiimgoodpack 2009 — 6y
0
Not everyone gets stuff the first time around. Your treating this like giving a 6th grader a problem for a college student and if they ask for help telling them they didn't even try. This person may have just started to script and doesn't know how to use the wiki. If so you can't just go off on them. DanzLua 2879 — 6y

Answer this question