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

How do i get my player in a Script?

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

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.

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 :)

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