I’m trying to fix my gun reload but it just stops working at the reload part. I’ve tried shortening my code with a function. Here’s my code:
local function reloadfunc(bulletcount, reloadbool)
if bulletcount == 0 then
reloadbool = true
print("Reloading...")
task.wait(5)
reloadbool = false
print("Done reloading!")
end
end
local ui = game.Players.LocalPlayer.PlayerGui:WaitForChild("Missed/Hit").TextLabel
local bullets = 5
local reload = false
local config = script.Parent.Configuration
script.Parent.Equipped:Connect(function(mouse)
mouse.Button1Down:Connect(function()
if bullets > 1 then
if reload == false then
local part = mouse.Target
if part ~= nil then
local hum = part.Parent:FindFirstChild("Humanoid")
if hum then
if part.Name == "Head" then
hum.Health -= config.Headshot.Value
game.ReplicatedStorage.GunGUI:FireServer(part.Parent, true, 1, config.Headshot.Value)
print("HEADSHOT")
bullets -= 1
ui.Text = "Hit ".. part.Parent.Name .. "!"
reloadfunc(bullets, reload)
elseif part.Name ~= "Head" then
hum.Health -= config.NormalShot.Value
game.ReplicatedStorage.GunGUI:FireServer(part.Parent, true, 1, config.NormalShot.Value)
print("Successful Shot")
bullets -= 1
ui.Text = "Hit ".. part.Parent.Name .. "!"
reloadfunc(bullets, reload)
end
elseif hum == nil then
print("Missed")
ui.Text = "You missed!"
bullets -= 1
reloadfunc(bullets, reload)
end
elseif part == nil then
print("Missed")
ui.Text = "You missed!"
bullets -= 1
reloadfunc(bullets, reload)
else
print("Missed")
ui.Text = "You missed!"
bullets -= 1
reloadfunc(bullets, reload)
end
end
end
end)
end)
Please help me. Thanks.