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

Why does this "shake" camera script only move once?

So I made a fully functioning camera shake script(local script), and it only seemed to just transport downwards once and then just stop. It didn't go up and down like it's supposed to. What problem is there? Thanks

local c = workspace.CurrentCamera
local plr = game.Players.LocalPlayer
math.randomseed(tick())

plr.ShakeCamera.OnClientEvent:connect(function()
	c.CameraType = "Scriptable"
	for i = 1,10 do
		if plr.Character:FindFirstChild("Torso") then
			c.CFrame = c.CFrame + Vector3.new(0,-4,0)
			print("down")
		end
			wait(.1)
			
		if plr.Character:FindFirstChild("Head") then
			c.CFrame = c.CFrame + Vector3.new(0,4,0)
			print("up")
		end
	end
	c.CameraType = "Custom"
end)

3 comments

0

You need a bigger loop. This will only run a second long.

1

You forgot to put another wait inside of the loop. So, the camera instantly goes back down when it is told to go up.

0

Overscores is right. All you need is just to put another wait() at the end of the loop.

1 answer

This new script works when i tested it.

local c = workspace.CurrentCamera
local plr = game.Players.LocalPlayer
math.randomseed(tick())

plr.ShakeCamera.OnClientEvent:connect(function()
    c.CameraType = "Scriptable"
    for i = 1,10 do
        if plr.Character:FindFirstChild("Torso") then
            c.CFrame = c.CFrame + Vector3.new(0,-4,0)
            print("down")
        end
            wait(.1)

        if plr.Character:FindFirstChild("Head") then
            c.CFrame = c.CFrame + Vector3.new(0,4,0)
            print("up")
        end
	wait(.1)
    end
    c.CameraType = "Custom"
end)

You forgot a second wait so it just instantly jumped down and up again so visual nothing happened.

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