How to check if the Magnitude of something is lowering by -1?

So I have this script where if the Magnitude lowers by -1 then I want it to print the magnitude like for every -1 for lets say 100 it does I want it to print it how would I do that this is my script

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

while wait() do
	local Magnitude = (HumanoidRootPart.Position - workspace.Baseplate.Position).Magnitude
	if Magnitude < Magnitude then
		print(Magnitude)
	end
end

There cant be magnitude -1 its impossible

lowers by -1 not is -1 silly boy

Can you please elaborate on what you’re trying to do, with your current explanation I can’t really understand what you mean.

In your code you’re basically comparing the same magnitudes, which are equal, so I don’t know what that is supposed to do either.

The magnitude is updating every Sec thats why its not printing

Its like to compare 1 to 1

Silly :smiley:

that is is not contributing to this thread or helpful in what to do to fix it.

so if the magnitude is 100 and it goes down by 1 to 99 then I want it to detect that change and print it

local Magnitude

while wait() do
If Magnitude == nil then
Magnitude = (HumanoidRootPart.Position - workspace.Baseplate.Position).Magnitude
end

if Magnitude < (HumanoidRootPart.Position - workspace.Baseplate.Position).Magnitude then
print(Magnitude)
Magnitude = (HumanoidRootPart.Position - workspace.Baseplate.Position).Magnitude
end
end

Just store a variable outside the loop that stores that last iteration’s magnitude, and then compare if the latest magnitude is not equal to the last iteration’s magnitude, from here you can use your basic logic to check if it is less than last time using an if statement and more if needed.

Like this?

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

local PreviousMagnitude = (HumanoidRootPart.Position - workspace.Baseplate.Position).Magnitude

while wait() do
	local Magnitude = (HumanoidRootPart.Position - workspace.Baseplate.Position).Magnitude
	if Magnitude < PreviousMagnitude then
		print(Magnitude)
	end
end

this does not detect a change of -1 just a change in magnitude

When the Magnitude variable is set it’s not going to update, each while true do run will be different. Look at it like it’s a function, it will not update.

make it set the previous magnitude in the while wait() loop

As I told just add another check for checking if it was a -1 change (simple logic, just subtract the latest Magnitude from PreviousMagnitude and if the result is 1 then it means there was a -1 change). Also you need to set PreviousMagnitude in the loop, otherwise it won’t update.

??? this

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

while true do
	local PreviousMagnitude = math.round((HumanoidRootPart.Position - workspace.Baseplate.Position).Magnitude)
	wait()
	local Magnitude = math.round((HumanoidRootPart.Position - workspace.Baseplate.Position).Magnitude)
	if Magnitude - PreviousMagnitude == 1 then
		print(Magnitude)
	end
end

You’re doing it mostly correctly, except the if statement part. Doing it this way, should do it:

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

while true do
	local PreviousMagnitude = math.round((HumanoidRootPart.Position - workspace.Baseplate.Position).Magnitude)
	wait()
	local Magnitude = math.round((HumanoidRootPart.Position - workspace.Baseplate.Position).Magnitude)
	if (PreviousMagnitude - Magnitude) == 1 then
		print(Magnitude)
	end
end

Also I don’t get why you’re using that math.round function, Its not needed.

But for my hot and cold map when they get closer it will switch from really blue to really red which is not a smooth tansition how do I make it a smooth transition

I don’t understand what you mean now, what is going to change from Really Blue to Really Red? I believe you’re wanting to change Color3 Property of some instance, couldn’t you use TweenService for smoothly making a transition?

So when someone is near the baseplate i want it to turn more and more red when someone is further away I want it to turn more blue but it goes from really red to really blue instantly not smoothly

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

while true do
	local PreviousMagnitude = math.round((HumanoidRootPart.Position - workspace.Baseplate.Position).Magnitude)
	wait()
	local Magnitude = math.round((HumanoidRootPart.Position - workspace.Baseplate.Position).Magnitude)
	if (Magnitude - PreviousMagnitude) == 1 then
		workspace.Baseplate.Color = Color3.fromRGB(0, 0, Magnitude)
	elseif (Magnitude - PreviousMagnitude) == -1 then
		workspace.Baseplate.Color = Color3.fromRGB(Magnitude, 0, 0)
	end
end
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

local color1 = Color3.new(1, 0, 0)
local color2 = Color3.new(0, 0, 1)
local maxDistance = (workspace.Baseplate.Size.X + workspace.Baseplate.Size.Z) / 2 -- Average distance based on XZ size.

while true do
    workspace.BasePlate.Color = color1:Lerp(color2, math.clamp((HumanoidRootPart.Position - workspace.Baseplate.Position).Magnitude / maxDistance, 0, 1))

    wait()
end

Something like this should work although I wrote it on phone without testing, tinker around with it.