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

Accessing Player's model from a normal script?

Hello, I have a script that requires the distance between the character (specifically the character's torso) and an object in Workspace. However, I can't find a way to access the Player's model! The code looks a bit like this (cropped to include relevant parts only):

while wait() do
	local magnitude = (script.Parent.Position - game.Players.LocalPlayer.Character.Torso.Position).magnitude
	if magnitude < 10 then
		--code
	elseif magnitude >= 10 then
		--code
	end
end

Obviously this doesn't work because LocalPlayer can only be used in LocalScripts. If anyone could find an answer, that'd be great. Thanks in advance!

1 answer

✓ Accepted answer

Well you could put your script in a LocalScript in StarterGui(:

I suggest adding 'wait(2)', or 'game.Players.LocalPlayer.Character:WaitFirChild("Torso")' to wait until the Character's torso loads, so you don't get any unecessary errors(:

2 comments

0

Aw man, does that mean it's impossible to use magnitude in a script? I appreciate the answer though. Thanks!

0

No, you can still use magnitude for this(: Just you have to think client side rather than server.

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