i know i know, title is very misleading
but basically, i’m making reloading right
reloading only runs when a boolvalue called reloading is set to true, via a while loop
to ensure that the reloading doesn’t continue after the gun gets unequipped, i’ve decided to put an AncestryChanged
event to use
well obviously silly me didn’t think this through and now i’m stuck at a probably very-simple-to-fix problem
i’ll comment out the unnecessary stuff
--local ReloadEvent = game:GetService("ReplicatedStorage"):WaitForChild("GunEvents").ReloadEvent
--local gunInfo = require(game:GetService("ServerScriptService"):WaitForChild("Weapons"):WaitForChild("Gun").GunStats)
--ReloadEvent.OnServerEvent:Connect(function(player)
local tool = player.Character:FindFirstChildOfClass("Tool")
local reloading = tool.Reloading.Value
--if tool.Bullets.Value > gunInfo[tool.Name]["MAX_BULLETS"] then player:Kick("Gluttony is a sin.") return end
--if reloading then player:Kick("Very funny.") return end
tool.AncestryChanged:Connect(function()
reloading = false
end)
-- // NORMAL RELOAD
--if tool.Bullets.Value > 0 then
reloading = true
--local NORMAL_MAGAZINE_PULL_TIME = gunInfo[tool.Name]["NORMAL_MAGAZINE_PULL_TIME"]
--local NORMAL_MAGAZINE_INSERT_TIME = gunInfo[tool.Name]["NORMAL_MAGAZINE_INSERT_TIME"]
--local NORMAL_FINISH_RELOAD_TIME = gunInfo[tool.Name]["NORMAL_FINISH_RELOAD_TIME"]
--local PullMagazineSound = tool.Magazine.PullMagSound
--local InsertMagazineSound = tool.Magazine.InsertMagSound
while reloading do
task.wait(NORMAL_MAGAZINE_PULL_TIME)
PullMagazineSound:Play()
tool.Bullets.Value = 0
task.wait(NORMAL_MAGAZINE_INSERT_TIME)
InsertMagazineSound:Play()
tool.Bullets.Value = gunInfo[tool.Name]["MAX_BULLETS"]
task.wait(NORMAL_FINISH_RELOAD_TIME)
reloading = false
end
-------------------------------------------------------------------------------
-- // EMPTY RELOAD
--elseif tool.Bullets.Value == 0 then
reloading = true
--local EMPTY_MAGAZINE_PULL_TIME = gunInfo[tool.Name]["EMPTY_MAGAZINE_PULL_TIME"]
--local EMPTY_MAGAZINE_INSERT_TIME = gunInfo[tool.Name]["EMPTY_MAGAZINE_INSERT_TIME"]
--local EMPTY_BOLT_PULL_TIME = gunInfo[tool.Name]["EMPTY_BOLT_PULL_TIME"]
--local EMPTY_FINISH_RELOAD_TIME = gunInfo[tool.Name]["EMPTY_FINISH_RELOAD_TIME"]
--local PullMagazineSound = tool.Magazine.PullMagSound
--local InsertMagazineSound = tool.Magazine.InsertMagSound
--local BoltPullSound = tool.Bolt.PullBoltSound
while reloading do
task.wait(EMPTY_MAGAZINE_PULL_TIME)
PullMagazineSound:Play()
tool.Bullets.Value = 0
task.wait(EMPTY_MAGAZINE_INSERT_TIME)
InsertMagazineSound:Play()
tool.Bullets.Value = gunInfo[tool.Name]["MAX_BULLETS"]
task.wait(EMPTY_BOLT_PULL_TIME)
BoltPullSound:Play()
task.wait(EMPTY_FINISH_RELOAD_TIME)
reloading = false
end
end
end)
i’m trying to avoid having a AncestryChanged
event along with a function between every single task.wait()
, is there a way i could have that event trigger whenever?