Distance between guis

image

How do I make a script that calculates the distance between the arrow and the star by a range of 0 to 1? (edited)

The reason is I want to make a multiplier and if you are on the red it returns 0 and if you hit green it returns 1 and orange is 0.5.

Thank you - BMWLux :pray: (far right for the arrow is 0.9 and far left is 0.1)

(untested but this should work)

-- https://devforum.roblox.com/t/lua-map-command/215342/15
-- Maps a number from one range to another:
-- [in_min, in_max] -> [out_min, out_max]
function map(x, in_min, in_max, out_min, out_max)
	return out_min + (x - in_min)*(out_max - out_min)/(in_max - in_min)
end

local star: GuiObject
local arrow: GuiObject

local dist = (arrow.AbsolutePosition - star.AbsolutePosition).Magnitude
local mapped = map(dist, 0, 9999, 1, 0)
2 Likes

i messed up the mapping, it should be fixed now

1 Like

Brilliant, I don’t know how you even did this but wow :clap: amazing

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.