Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago
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

Log in to vote
1
Answered by
Prestory 1395 Moderation Voter
4 years ago

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)

Ad

Answer this question