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

How to aim down sights on a pistol?

Asked by 6 years ago
Edited 6 years ago

So, I am trying to make a pistol on which you can aim down sights. I tried tinkering with the CurrentCamera to try to do that, but I didn't get the results I wanted. Can someone help me with this?

Code:

mouse.Button2Down:connect(function() print("Aiming down sights!") if not ads then cam.CameraSubject = gun.Union cam.CFrame = gun.Union.CFrame ads = true else cam.CameraSubject = plr.Character.Humanoid cam.CFrame = plr.Character.HumanoidRootPart.CFrame ads = false end end)

1 answer

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

The problem with your code is that you’re using the KeyDown event which is deprecated, and you’re using the connect method when it’s Connect.

gun.Equipped:Connect(function(mouse)
    mouse.Button2Down:Connect(function()
        if not ads then 
            cam.FieldOfView = 10
            cam.CameraSubject = gun.Union
            cam.CFrame = gun.Union.CFrame
            ads = true
        else
            cam.CameraSubject = plr.Character.Humanoid
            cam.CFrame = plr.Character.HumanoidRootPart.CFrame
            ads = false
        end
    end)

    game:GetService("ContextActionService"):BindAction( -- use this instead of keydown.
    "Reload", 
    reload, 
    true, 
    Enum.KeyCode.R
)

end)
0
I don't care if it's deprecated, I find the "non-deprecated" or whatever they are called methods way too complicated duje225_awesome 10 — 6y
0
Also, KeyDown works just fine for me. I'm just not sure how to do the ADS part properly. duje225_awesome 10 — 6y
0
The deprecated code doesn’t work anymore. It causes lag and delay, and just doesn’t work. Why use old code over new code. User#19524 175 — 6y
0
The ContextActionService has a more accurate way of getting user input, while the KeyDown event doesn’t. User#19524 175 — 6y
0
Depricated code isn't a good choice it take longer to execute and can cause more problems. Sergiomontani10 236 — 6y
Ad

Answer this question