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

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

Asked by 8 years ago

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)
0
You need a bigger loop. This will only run a second long. Async_io 908 — 8y
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. Overscores 381 — 8y
0
Overscores is right. All you need is just to put another wait() at the end of the loop. NathanAdhitya 124 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

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.

Ad

Answer this question