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

How do i get my player in a Script?

Asked by 9 years ago

Its not a local script so i did this:

player = script.Parent.Parent.Parent

--my script is in a screenGui that's in StarterGui. Did i do it right?

2 answers

Log in to vote
1
Answered by 9 years ago

Yes although scripts should generally never be located in screen GUI's it's a bad practice you should only use regular scripts inside Server sided environments not inside client (local) environments.

Ad
Log in to vote
0
Answered by
woodengop 1134 Moderation Voter
9 years ago

That way is Valid too, and useful for making coding shorter and easier. There are Different ways where you can get the player as well , And remember that the way I'm doing it with a LocalScript can not be operated with a Normal Script, same with a Normal Script.

LocalScript

local player = game.Players.LocalPlayer--this would get the LocalPlayer(you) and only works on a local script f.y.i

Script

game.Players.PlayerAdded:connect(function(player)-- the player inside the Parenthesis, is the player that Joined(you, or some other player)
    --etc
end)

These ways are a bit long, But if you want to make your coding easier then, you would use:

player = script.Parent.Parent.Parent--Easier :)

Answer this question