Magnitude Multiple Parts
Magnitude using one singe script and pairs seems to be a bit confusing.
I was wondering how I could make a gui that pops up when you get near an object. Once you leave the radius it disappears… But also if you go near a separate part then a different gui will pop up.
I have the gui’s etc… set up, but whenever use i,v in pairs to do this it glitches out because I’m to far away from the second part (in result closing the gui)
Please notice!! the following code is a test product and is very messy or non-efficient.
if active == false then
print('isnt false, processing')
if active == false then
for i,v in pairs(game:GetService("Workspace"):FindFirstChild("RadiusDetections"):GetChildren()) do
if (lpchar.HumanoidRootPart.Position - v.Position).Magnitude <= tonumber(v.Radius.Value) then
print('activating')
if returnvalue == false then
active = true
returnvalue = true
local gui = lp.PlayerGui:WaitForChild("DialogGUI")
gui.Main.Header.Text = tostring(v.ChatDialog["1"].Header.Value)
gui.Main:TweenPosition(UDim2.new(0.5,0,0.895,0),"Out","Back",0.5,true)
for i = 1, #v.ChatDialog["1"].Body.Value do
gui.Main.Body.Text = string.sub(v.ChatDialog["1"].Body.Value,1,i)
wait()
end
end
end
if (lpchar.HumanoidRootPart.Position - v.Position).Magnitude > tonumber(v.Radius.Value) then
print('deactivating')
if returnvalue == true then
local gui = lp.PlayerGui:WaitForChild("DialogGUI")
gui.Main:TweenPosition(UDim2.new(0.5,0,1.2,0),"In","Back",0.5,true)
returnvalue = false
wait(0.5)
gui.Main.Header.Text = "Error"
gui.Main.Body.Text = "Error"
active = false
end
end
end
end
end