im making a gun system and trying to make the fire rate part of it
but… the time is uneven, somehow.
local weapon = script.Parent
local rp = game:GetService("ReplicatedStorage")
local equipped = false
local equipAnim = script:FindFirstChild("WeaponEquip")
local idleAnim = script:FindFirstChild("WeaponIdle")
local unequipAnim = script:FindFirstChild("WeaponUnequip")
local shootAnim = script:FindFirstChild("WeaponShoot")
local weaponClone = rp.Guns:WaitForChild("Pistol") -- change this to the weapon model
local weaponParticles = weapon:WaitForChild("GunParticle")
local ShotSound = weapon:WaitForChild("ShotSound")
local canShoot = false
local gunFireRate = 1
weapon.Activated:Connect(function()
local hum = script.Parent.Parent.Humanoid
if canShoot == false then
canShoot = true
-- particles
local muzzle = weaponParticles:WaitForChild("MuzzleFlash")
local sparkle = weaponParticles:WaitForChild("Sparkle")
local smoke = weaponParticles:WaitForChild("Smoke")
-- anim tracks
local shootAnimTrack = hum:LoadAnimation(shootAnim)
shootAnimTrack:Play()
ShotSound:Play()
muzzle.Enabled = true
sparkle.Enabled = true
smoke.Enabled = true
wait(0.05) -- change as needed
muzzle.Enabled = false
sparkle.Enabled = false
smoke.Enabled = false
end
task.wait(gunFireRate)
print(gunFireRate)
canShoot = false
end)
Try printing the value of canShoot at the beginning of weapon.Activated to debug. That’s my best idea as I don’t necessarily see anything wrong with the code. However, it’s a hard read personally.
I don’t know of that you have an FPSUnlocker enabled, but I believe task.wait() is frame rate dependent, so changing it to wait() could help. Might be wrong.
That’s where your inconsistencies should be coming from. Most of the time, anything that has to do with the player should be handled on the client and not the server.