Can't put decimal numbers in CameraOffset XYZ axes?

My intention is to make the player’s camera shake a bit. The script below:

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()

while true do
	for i = 1, 20 do
		wait()
		char.Humanoid.CameraOffset = Vector3.new(math.random(-0.5, 0.5),math.random(-0.5, 0.5),math.random(-0.5, 0.5))
	end
	char.Humanoid.CameraOffset = Vector3.new(0,0,0)
	wait(math.random(0, 3))
end

doesn’t work unless the XYZ axes are integers. However, integers are a bit too much for the gentle camera shake. Please help.

I think you could use “math.floor()” to round integers with decimal numbers into int64s, i haven’t tested it but it could work.

How does math.floor() work? I’ve never used it before.

math.floor rounds a number down to the integer below it. For example, 1.2 would go to 1, 5.9 would go to 5. I am wondering, why can’t you use decimals?

For example, if you use math.floor(42.6) on a integer with decimal numbers which is 42.6, it would round it to 43.

If I use decimals nothing happens

That’s incorrect. math.round() would do that, not math.floor.

never knew that but i learn something new everyday.

Anyways, that could work.

i don’t think math.floor or round would help much would it

You should be able to use decimals. That is what puzzles me. Are you receiving any errors?

math.random() does not work with decimals. you can first generate a number with math.random(), then divide the number to get a smaller number.

local a = math.random(-50,50)/100
local b = math.random(-50,50)/100
local c = math.random(-50,50)/100
char.Humanoid.CameraOffset =  Vector3.new(a,b,c)

no errors. no nothing. screen is normal

Actually, is there an error inside the error output? In other cases, if that isn’t supposed to be happening for you read all the stuff in the knowledge of ROBLOX programming codes, you should probably post it in engine bugs where decimals don’t work.

Edit: Nevermind, i just read the post where you said there’s no errors.

Thanks all. All your work is highly appreciated.

Here, use the following code:

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()

function GetOffset(a)
	return (math.random(1, a * 1000) / 1000) - a / 2
end

while true do
	local hum = char:WaitForChild("Humanoid")
	
	for i = 1, 20 do
		local function GetShake()
			return (1 - math.abs(10 - i) / 10) * GetOffset(0.5)
		end
		
		wait()
		hum.CameraOffset = Vector3.new(GetShake(),GetShake(),GetShake())
	end

	hum.CameraOffset = Vector3.new(0,0,0)
	wait(math.random(0, 3))
end

I spiced things up with some math, which intensifies the shaking and then slows it down in each loop. I can attest that this works, with decimals, as I have tested it myself in studio.

Clip:

1 Like