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

How to properly use magnitude?

This script is supposed to increase if you get farther away from the brick, ad decrease as you approach it. Just so you can see it wherever you go. My problem is that it keeps increasing and decreasing randomly. Tips?

local Sizing = coroutine.wrap(function()
	pl = game.Players.LocalPlayer
	c = game.Workspace.CurrentCamera
	s = c.Part
	f = s.Rank.Frame
	old = 0
	while true do
		wait()
		if (old < (pl.Character.Head.Position - s.Position).magnitude) then
			f.Size = f.Size - UDim2.new(.1,0,.1,0)
			old = (pl.Character.Head.Position - s.Position).magnitude
			wait()
		elseif (old > (pl.Character.Head.Position - s.Position).magnitude) then
			wait()
			f.Size = f.Size + UDim2.new(.1,0,.1,0)
			old = (pl.Character.Head.Position - s.Position).magnitude
		elseif (old == (pl.Character.Head.Position - s.Position).magnitude) then
			wait()
        end
    end
end)
        game.Lighting.Part:clone().Parent = game.Workspace.CurrentCamera
        Sizing()

1 answer

✓ Accepted answer

This is a problem since moving close and far by different rates all change the size at the same rate.

You should instead have a function for size in terms of distance (this will also simplify your script):

Something like this:

local dist = (pl.Character.Head.Position - s.Position).magnitude);
f.Size = UDim2.new( (4 + dist) * .01 , 0 , (4 + dist) * .01    );

Which should approximate undoing perspective sizing (although there should probably be a cap on size using math.min)


Your question wasn't described too well, so I'm not sure if I've got it right. Please let me know if this isn't what you were looking for.

1 comment

1

Thanks a lot. +1'd and Accepted.

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