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

How to I make my first person gun script snappier?

Asked by 3 years ago

SCRIPT:

local player = game.Players.LocalPlayer
local char = player.Character
local cam = workspace.Camera
local arms = game.ReplicatedFirst.Arms:Clone()
local MyGun = script.Parent
local GunHandle = MyGun:WaitForChild("Handle")
arms.Parent = cam
local Humanoid = arms.Humanoid
local IdleAnimation = script.IdleAnim
local ShootingAnimation = script.ShootAnim
local ShootAnimTrack = Humanoid:LoadAnimation(ShootingAnimation)
local IdleAnimTrack = Humanoid:LoadAnimation(IdleAnimation)
IdleAnimTrack:Play()
local mouse = player:GetMouse()

mouse.Button1Down:Connect(function()
    ShootAnimTrack:Play()
    game.ReplicatedStorage.Shoot:FireServer(mouse.Hit.p)
end)

game:GetService("RunService").Stepped:Connect(function()
    for i = 1, 100 do
        arms:SetPrimaryPartCFrame(cam.CFrame * CFrame.new(0,-2,-2.5) * CFrame.Angles(0,0,0))
    end
end)    

I am trying to make a gun script and it works, but the issue is that when you turn the camera, it looks clunky and it stutters. Is there any way I can make it more snappy?

1
Just out of curiosity, have you tried using `RenderStepped` instead of `Stepped`? Gey4Jesus69 2705 — 3y
1
Woah, that actually worked. If you want, you can make an answer so that I can give you and I karma. Thanks! :) SussiestBalss 40 — 3y

2 answers

Log in to vote
1
Answered by 3 years ago

Try using RenderStepped instead of Stepped.

game:GetService("RunService").RenderStepped:Connect(function()
    for i = 1, 100 do
        arms:SetPrimaryPartCFrame(cam.CFrame * CFrame.new(0,-2,-2.5) * CFrame.Angles(0,0,0))
    end
end)    
Ad
Log in to vote
1
Answered by 3 years ago

I already found out this solution due to Gey4Jesus69. When using run service, use RenderStepped instead of Stepped, it's more reliable.

1
Sorry, I didn't care to try to explain the reason why it worked, because I know very little about it myself. According to the wiki, RenderStepped fires every frame prior to the frame being rendered. However, Stepped fires every frame prior to the physics simulation. I assume Stepped probably avoids actual latency issues, whereas RenderStepped is more beneficial for anything regarding framerate Gey4Jesus69 2705 — 3y
1
That is why I suggested RenderStepped, because your issue isn't actually focused on physics in-game, rather the way your movement looks Gey4Jesus69 2705 — 3y
0
Yeah, that makes sense. Thank you for the help and I also learned something new! SussiestBalss 40 — 3y

Answer this question