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

How do i get a player into a server script? [closed]

Asked by
sproxa 7
6 years ago

This question already has an answer here:

How do i get a player into a server script?

i have been trying to do it for a while now but i cant find out how

Marked as Duplicate by User#5423

This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.

Why was this question closed?

1 answer

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

There are various ways to get the Player in a ServerScript:

1. Using the PlayerAdded event.

You can make up a function called with this event, which you can grab the player from the parameter provided by the event.

game:GetService("Players").PlayerAdded:Connect(function(player)
    -- code
end)

2. Getting the player when having the character.

If you have the character you can also get the player with this built-in method in the Players' Service.

local player = game:GetService("Players"):GetPlayerFromCharacter(character)

There are more ways to get the player in specific contexts, but I'd recommend to use PlayerAdded. Have a good day!

Ad