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

Why is this script that is checking the player's distance from a part not working?

Asked by 4 years ago

Hello!

So in my game I need to check if the player is a certain distance away from a part to display a gui, but the problem is, checking the distance from the part isn't working and no errors are showing up in the output. Here's my localscript.

local distance = workspace.distance

local player = game.Players.LocalPlayer
local part1 = player.Character.Fedora

local part2 = workspace["Aseroid Groups"].Model.AsteroidNotice

while wait() do
    local magnitude = (part1.Position - part2.Position).magnitude
    distance.Value = part2.Name.." is "..math.floor(magnitude).." studs away."
    --print(distance)
end

I apologize if my code is unorganized or if the error is obvious...I didn't get much sleep last night. Also please don't bug me about the spelling error on line 6 );

Thanks!

-GreenGrassGamer2008

0
add a wait(1) at the top to let the character load, make sure its in a local script, also make sure distance is a string value and every thing should work. mixgingengerina10 223 — 4y
0
still didn't work. weird proqrammed 285 — 4y

Answer this question