Decrease Slower

I’m trying to create a system where a number decreases slowly based on a variable. However, I’ve encountered a problem where it works as expected when the number is small (e.g., 0.1), but when the number is larger (e.g., 100), it decreases much faster. I want both small and large numbers to decrease at the same rate. Here’s the script for context:

local part1 = game.Workspace:WaitForChild("MainEntity"):WaitForChild("Ent")
local cam = workspace.CurrentCamera

game["Run Service"].RenderStepped:Connect(function()
	local part2 = game.Players.LocalPlayer.Character.HumanoidRootPart
	local distance = (part1.Position - part2.Position).Magnitude

	local strength = 100

	local dist = strength *100 - distance / 0.1

	local max = math.max(dist, 0)
	print(max)
end)
2 Likes

If you use the distance of 2 objects then the further away the 2 objects are the higher the variable “distance” will be. If you want it to decrease at the same rate don’t use distance; just use a constant number. But if you use a constant number with RenderStepped() then you will have to times it by delta time so it moves at the same rate for all frame rates.

1 Like

So, for context, like this?

game["Run Service"].RenderStepped:Connect(function(delta)
	local distance = (part1.Position - part2.Position).Magnitude
	
	local realDist = dist * delta -- Multiplying it

Also, how would your “constant number” ideia work?

1 Like

if you want a constant speed you need a constant number, and distance wont be constant (from what i can tell in your script).

local speedOfCamConst = 10 --You can change this
local part1 = game.Workspace:WaitForChild("MainEntity"):WaitForChild("Ent")
local cam = workspace.CurrentCamera

game["Run Service"].RenderStepped:Connect(function(dt)
	
	local speedOfCam = speedOfCamConst * dt -- this is the relative speed so it wont go slower/faster depending on frame rate
	
	local part2 = game.Players.LocalPlayer.Character.HumanoidRootPart
	local distance = (part1.Position - part2.Position).Magnitude

	local strength = 100

	--local dist = strength *100 - distance / 0.1
	
	local dist = strength *100 - speedOfCamConst / 0.1 
	
	local max = math.max(dist, 0) --this will return a constant value
	print(max)
end)

However im not really sure what you are trying to achieve, as i cant see the full script but i think the extract i sent is what youre trying to achieve

1 Like

I don’t have a complete script yet, but I’m working on a feature where the camera shakes more when you get closer to a part and shakes less as you move farther away.

1 Like