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

Magnitude doesn't seem to be working?

Ok so I'm working on a small thing that uses magnitude. Basically in workspace there's a folder that contains parts which are all named the same thing however the parts are spread around the map. The local script gets the folder and checks whether the name of the part is "Hello," if the name is "Hello," then the local script makes a simple text label visible. Hope this kind of gives you an idea of what I'm trying to do.

while wait() do
	local checkPart = game.Workspace.Wow:GetChildren() --Folder in workspace
	if checkPart.Name == "Hello" then
	local dis = (game.Workspace.checkPart.Position - game.Players.LocalPlayer.Character.HumanoidRootPart.Position).magnitude
	if dis <= 10 then
		script.Parent.TextLabel.Visible = true
		wait()
	end
	if dis >= 9 then
		script.Parent.TextLabel.Visible = false
		wait()
	end
	wait()
	end
	wait()
	end

1 comment

0

if you are waiting until the part is a certain distance from the player use "repeat; (code here); until ".. Seems more of an >>XY problem<< as you can easily check if .magnitude works by printing it out.

1 answer

✓ Accepted answer

I edited your script a bit the script is using "For loops" to loop throw all the parts in the folder and checks if the name is correct (hello) its not perfect but it will take me time to fix the Flashes (i know what is the problem)

while true do
	for i,v in pairs(game.Workspace.Wow:GetChildren()) do
		if v.Name == "Hello" then
			local dis = (v.Position - game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart").Position).magnitude
		    if dis <= 10 then
		        script.Parent.TextLabel.Visible = true
		        wait()
		    else 
		        script.Parent.TextLabel.Visible = false
		        wait()
		    end
		end
	end
end	

ok finally I got the fixed version

local c
script.Parent.TextLabel.Visible = false
while true do
	for i,v in pairs(game.Workspace.Wow:GetChildren()) do
		wait()
		if v.Name == "Hello" then
			local dis = (v.Position - game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart").Position).magnitude
		    if dis <= 10 then
		        script.Parent.TextLabel.Visible = true
		        wait()
				c = i
		    else 
				if i == c then
			        script.Parent.TextLabel.Visible = false
			        wait()
					local c = nil
				end
		    end
		end
	end
end	

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