I am making a ray gun that has a magazine which the player reloads. After running into issues with server yields, I adjusted everything to run on more localized yields.
However, the issue now is that there is no wait() before the magazine is reloaded and so the player can instantly shoot again. When the function is called, we check if it has been long enough by comparing tick() to reloadtick and the reloadtime value. If I were to check the tick() again to see if it has been long enough to complete the reload, wouldn't that just return false? I'm not sure how to proceed without a wait() that would clog the server side of this gun.
local function reload(player, gun)
local active = gun.gunstats.Active
if active.Value == true and reloaddebounce == false then
reloaddebounce = true
local reloadtime = gun.gunstats.Reloadtime
local magammo = gun.gunstats.Mag
local maximum = gun.gunstats.Maximum
local reloadtick = 0
if magammo.Value < maximum.Value and tick() - reloadtick >= reloadtime.Value then --cant reload when full
reloadtick = tick()
changetoreload:FireClient(player)
changecursortoreload:FireClient(player)
magammo.Value = 0
gun.phalanx.Magazine.Transparency = 1
gun.Handle.Reloadsound:Play()
--wait(reloadtime.Value) --the issue is here
reloaddebounce = false
gun.phalanx.Magazine.Transparency = 0
magammo.Value = maximum.Value
end
end
end
reloadevent.OnServerEvent:Connect(reload)

1 comment
Thank you, this is useful. I'm not sure I understand them very well though. When I do as you said I get an error cannot resume dead coroutine.