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

What is wrong with this camera shake script and why do I keep getting this error?

while wait() do
local pos = Vector3.new(0, 10, 0)
local RandomizerX = math.random(-1,1)	
local RandomizerY = math.random(-1,1)	
local RandomizerZ = math.random(-1,1)	


local lookAt = Vector3.new((workspace.CurrentCamera.CFrame + RandomizerX), 0, (workspace.CurrentCamera.CFrame + RandomizerZ))
local cameraCFrame = CFrame.new(pos, lookAt)
workspace.CurrentCamera.CFrame = cameraCFrame
end

Error:

18:45:12.756 - Players.Thesquid13.PlayerGui.LocalScript:8: bad argument #2 to '?' (Vector3 expected, got number)
18:45:12.756 - Stack Begin
18:45:12.757 - Script 'Players.Thesquid13.PlayerGui.LocalScript', Line 8
18:45:12.757 - Stack End

1 answer

✓ Accepted answer

It is giving you an error because you are adding on the values incorrectly since you are using Vector3.new you cant just do

+ 1,2,3

Instead you have to use Vector3.new like this

+ Vector3.new(1,2,3)

The code below should work

while wait() do
local pos = Vector3.new(0, 10, 0)
local RandomizerX = Vector3.new(math.random(-1,1))   
local RandomizerY = Vector3.new(math.random(-1,1))   
local RandomizerZ = Vector3.new(math.random(-1,1))   


local lookAt = Vector3.new((workspace.CurrentCamera.CFrame + RandomizerX), 0, (workspace.CurrentCamera.CFrame + RandomizerZ))
local cameraCFrame = CFrame.new(pos, lookAt)
workspace.CurrentCamera.CFrame = cameraCFrame
end

(Not tested might not be 100% accurate)

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