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

Why isn't this LocalScript shaking the script when the player left clicks?

Asked by
Lyphios 77
3 years ago

so this is a LocalScript inside of StarterCharacterScripts, but since I'm paranoid I also put it into StarterPlayerScripts. It's meant to shake the screen and change the camera's angle when the player left clicks.

local character = script.Parent
local plr = game.Players[character.Name]
local mouse = plr:GetMouse()

function Shake()

    for i = 0, 1, 0.2 do
    workspace.CurrentCamera.CFrame = workspace.CurrentCamera.CFrame * CFrame.Angles(.02,math.rad(.1),0.02)
    game:GetService("RunService").RenderStepped:Wait()
    end
    for i = 0 ,1, 0.2 do
    workspace.CurrentCamera.CFrame = workspace.CurrentCamera.CFrame * CFrame.Angles(-.01,math.rad(-.1),-0.01)
    game:GetService("RunService").RenderStepped:Wait()
    end

        mouse.Button1Down:Connect(function()
            Shake()
        end)
    end


What did I do wrong?

0
any errors? Dan_PanMan 227 — 3y
0
No, nothing actually. Lyphios 77 — 3y
0
Well, you're calling the function inside of the function itself. Take the mouse.Button1Down part out of it and put it below it. killerbrenden 1537 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago
local character = script.Parent
local plr = game.Players[character.Name]
local mouse = plr:GetMouse()

function Shake()
     for i = 0, 1, 0.2 do
        workspace.CurrentCamera.CFrame = workspace.CurrentCamera.CFrame * CFrame.Angles(.02,math.rad(.1),0.02)
        game:GetService("RunService").RenderStepped:Wait()
     end
     for i = 0 ,1, 0.2 do
            workspace.CurrentCamera.CFrame = workspace.CurrentCamera.CFrame * CFrame.Angles(-.01,math.rad(-.1),-0.01)
        game:GetService("RunService").RenderStepped:Wait()
    end
end

mouse.Button1Down:Connect(function()
    Shake()
end)
0
I found made another solution, but this also worked so thanks Lyphios 77 — 3y
Ad

Answer this question