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

why won't my camera move (localscript)?

Asked by 5 years ago

I need my camera to move up and down during the animation (trying to get a shake effect)? Warning long!

LocalScript:

--Starting Varibles
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local camera = game.Workspace.CurrentCamera


--Keypressed
mouse.KeyDown:connect(function(key)
    --Find keybind
    local keybind = script.Parent.KeybindText.Text
    --Check keybind
    if key:lower() == keybind or key:upper() == keybind then
        --Camera
        script.Parent.Parent.Parent.OnOff.Visible = false
        game.Workspace[player.Name].Humanoid.WalkSpeed = 0
        local newCamera = Instance.new("Part", game.Workspace[player.Name].Head)
        newCamera.Name = "localNewCamera"
        newCamera.Anchored = true
        newCamera.CanCollide = false
        local oy = game.Workspace[player.Name].Head.Orientation.Y
        local ox = game.Workspace[player.Name].Head.Orientation.Y
        wait(0.01)
        newCamera.Orientation = Vector3.new(0,oy -180,0)
        newCamera.Transparency = 1
        wait(0.01)
        local x = game.Workspace[player.Name].Head.Position.X
        local y = game.Workspace[player.Name].Head.Position.Y
        local z = game.Workspace[player.Name].Head.Position.Z
        wait(0.01)
        newCamera.Position = Vector3.new(x,y -1,z - 5)
        wait(0.01)
        camera.CameraType = "Scriptable"
        camera.CFrame = game.Workspace[player.Name].Head.localNewCamera.CFrame
        --Animation
        local animation = Instance.new("Animation")
        animation.AnimationId = "rbxassetid://2544696183"
        local humanoid = game.Workspace[player.Name]:WaitForChild("Humanoid")
        wait(0.01)
        local track = humanoid:LoadAnimation(animation)
        wait(0.2)
        track:Play()
        for i = 1,20 do
            wait(0.1)
            local nx = newCamera.Position.X
            local ny = newCamera.Position.Y
            local nz = newCamera.Position.Z
            wait(0.1)
            newCamera.CFrame = CFrame.new(nx,ny +0.1,nz)
            wait(0.1)
            newCamera.CFrame = CFrame.new(nx,ny -0.1,nz)
        end
    end
end)
0
Try and run a game and look at the output for the errors. OnceLegend 3 — 5y

Answer this question