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

How do you find a player in the workspace?

I am using a regular script in the workspace, but I need to find the character. How would I do that?

I tried

local char = game.Players.LocalPlayer.Character
local player = game.Players:GetPlayerFromCharacter(char)

But no success. Any help would be appreciated (and no, these variables are not done within a function)

WOuld I just use script.Parent>parent etc. until i reach the player?

1 answer

You can't use local player = game.Players.LocalPlayer if you even have that line then it won't work. That line is only used in Local Scripts. You need to explain what your trying to do. You can only find the character through the player which is in the game service called Players. If you are trying to animate by clicking a button then put a local script inside of the button. If you just want to find a player through a regular script then try something like this;

game.Players.PlayerAdded:Connect(function(plr) -- plr is the player variable 
	local c = plr:GetPlayerFromCharacter()
	-- your code
end)

if you want a specific player then check it's name.

If this helped then please accept answer,

have fun developing! Good Luck!

1 comment

0

or you can say plr.Character

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