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

Accessing Player's model from a normal script?

Asked by 9 years ago

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

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

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

0
Aw man, does that mean it's impossible to use magnitude in a script? I appreciate the answer though. Thanks! IcyArticunoX 355 — 9y
0
No, you can still use magnitude for this(: Just you have to think client side rather than server. Goulstem 8144 — 9y
Ad

Answer this question