What do you want to achieve? I want the opposite of a number example: 1 would be 0 and 0 would be 1.
What solutions have you tried so far? I have tried using math.abs but that just gave me the same number and other posts that looked similar didnt have what i needed.
my script: (local script)
local char = game.Players.LocalPlayer.Character
while wait() do
local Distance = (char.HumanoidRootPart.Position - game.Workspace.ScreenShaker.Position).Magnitude
local Rounded = math.round(Distance)
local intensity = math.abs(1 - Rounded) --this is the line where i get problems
print(intensity)
end
it prints a low number when i am close to the part and a high number when im far away from it.
this wont work as the screenshake should be intense when im close to the part and not when im far away from it.
You can add a radius for linear interpolation for the screenshake effect, assuming 0 is highest and 1 is the lowest intensity for your effect.
local ScreenShakeRadius = 50
local dist = (HumRp.Position - workspace.ScreemShaker.Position).Magnitude
if dist > ScreenShakeRadius then
--cancel the effect and don't continue with the bottom
end
local intensity = dist / ScreenShakeRadius
intensity = math.abs(intensity - 1) --inverse
if intensity < 1 then
--do the screen effect when it's between 0 and 1
end
That worked! i just had to clamp it to 0 and the rolloff so that it doesnt go into the negatives
Edit: now the while loop doesnt stop:
local char = game.Players.LocalPlayer.Character
game.Workspace.ChildAdded:Connect(function(child)
if child.Name == "A-10" or child.Name == "X-10" then
while child do
wait()
local Distance = (char.HumanoidRootPart.Position - child.Position).Magnitude
local Rounded = Distance
local rolloff = 120
local intensity = math.random(0.1, math.clamp(rolloff, 0, 1))
local final = rolloff - Rounded
local clamp = math.clamp(final, 0, intensity)
char.Humanoid.CameraOffset = Vector3.new(math.random(0, clamp), math.random(0, clamp), math.random(0, clamp))
end
end
end)
the “A-10” or “X-10” are the monters and they get cloned from ReplicatedStorage in a script. at the end they get destroyed but the while loop doesnt stop.