ok this is a long one, so if you don’t have much time don’t read this. This bug has been haunting me for days.
I’m making guns for my game, and I have a big problem. When I switch guns at a certain time the reload sequence carries over to the other gun. Here’s a demonstration.
https://gyazo.com/ab0f4a96f2abf6c0f794bd52cb423e15
I have no clue what could be causing this bug, I have added reload canceling scripts to fix this and it still doesnt even fix. I am just gonna paste the whole script. (the scripts for the guns are the same with editing variables)
local Player = game.Players.LocalPlayer
local tool = script.Parent
local Mouse = Player:GetMouse()
local famasreloading = false
local famasfiring = false
local UIS = game:GetService("UserInputService")
local PlayerGUI = Player:WaitForChild("PlayerGui")
local NameGUI = PlayerGUI:WaitForChild("ScreenGui").name
local AmmonGUI = PlayerGUI:WaitForChild("ScreenGui").ammo
local ammoevent = game.ReplicatedStorage.ammo
local famasreloadcanceled = false
local damageevent = game.ReplicatedStorage.damage
local famasdebounce = false
local pulloutrifleanim = game.Workspace:WaitForChild("Pull Out Rifle")
local rifleidleanim = game.Workspace:WaitForChild("Rifle Idle")
local drawgunanim = game.Workspace:WaitForChild("Draw Gun")
local firegunanim = game.Workspace:WaitForChild("Fire GUn")
local drawgun = Player.Character.Humanoid:LoadAnimation(drawgunanim)
local riflepull = Player.Character.Humanoid:LoadAnimation(pulloutrifleanim)
local rifleidle = Player.Character.Humanoid:LoadAnimation(rifleidleanim)
local firegun = Player.Character.Humanoid:LoadAnimation(firegunanim)
local riflesound = game.Workspace["FAMAS fire"]
local hitmarker = game.Workspace.hitmarker --sounds
local rifleequip = game.Workspace["Rifle equip"]
local reload = game.Workspace["Galil Reload"]
local Famasmagsize = 30
local Famasreserve = 0
local Famasmag = Famasmagsize
function round(num)
return math.floor(num * 10) / 10;
end;
tool.Activated:Connect(function()
if famasreloading == true then
famasreloadcanceled = true
end
reload:Stop()
famasfiring = true
drawgun:Play()
firegun:Play()
while famasfiring == true and famasreloading == false do
if Famasmag > 0 then
local Target = Mouse.Target
if Target == nil then
Player.Character.Humanoid.WalkSpeed = runningspeed
Player.Character.Humanoid.JumpPower = 0
Famasmag = Famasmag - 1
AmmonGUI.Text = (Famasmag..'/'..Famasreserve)
riflesound:Play()
elseif Target.Parent:FindFirstChild("Humanoid") then
Player.Character.Humanoid.WalkSpeed = runningspeed
Player.Character.Humanoid.JumpPower = 0
Famasmag = Famasmag - 1
AmmonGUI.Text = (Famasmag..'/'..Famasreserve)
damageevent:FireServer(Target, damage)
riflesound:Play()
hitmarker:Play()
elseif Target.Parent.Parent:FindFirstChild("Humanoid") then
Player.Character.Humanoid.WalkSpeed = runningspeed
Player.Character.Humanoid.JumpPower = 0
Famasmag = Famasmag - 1
AmmonGUI.Text = (Famasmag..'/'..Famasreserve)
damageevent:FireServer(Target, damage)
riflesound:Play()
hitmarker:Play()
else
Player.Character.Humanoid.WalkSpeed = runningspeed
Player.Character.Humanoid.JumpPower = 0
Famasmag = Famasmag - 1
AmmonGUI.Text = (Famasmag..'/'..Famasreserve)
riflesound:Play()
end
end
wait(firerate)
end
end)
tool.Deactivated:Connect(function()
firegun:Stop()
Player.Character.Humanoid.WalkSpeed = 16
Player.Character.Humanoid.JumpPower = 50
famasfiring = false
end)
tool.Unequipped:Connect(function()
rifleidle:Stop()
firegun:Stop()
NameGUI.Visible = false
AmmonGUI.Visible = false
if famasreloading == true then
famasreloading = false
famasreloadcanceled = true
reload:Stop()
Player.Character.Humanoid.WalkSpeed = 16
Player.Character.Humanoid.JumpPower = 50
Famasmag = Famasmag
end
Player.Character.Humanoid.WalkSpeed = 16
Player.Character.Humanoid.JumpPower = 50
famasfiring = false
end)
tool.Equipped:Connect(function()
famasreloadcanceled = true
famasreloadcanceled = false
damage = 10
reloadcount = 2.5
runningspeed = 5
firerate = 0.2
local GunName = "Famas"
NameGUI.Visible = true
AmmonGUI.Visible = true
NameGUI.Text = GunName
AmmonGUI.Text = (Famasmag..'/'..Famasreserve)
rifleequip:Play()
riflepull:Play()
wait(0.1)
rifleidle:Play()
end)
UIS.InputBegan:Connect(function(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.R then
if Famasmag ~= Famasmagsize and famasreloading == false and famasdebounce == false then
famasdebounce = true
reloadcount = 2.5
famasreloading = true
reload:Play()
Player.Character.Humanoid.WalkSpeed = runningspeed
Player.Character.Humanoid.JumpPower = 0
repeat
if famasreloading == true then
AmmonGUI.Text = "Reloading "..reloadcount
reloadcount = reloadcount - 0.1
Player.Character.Humanoid.WalkSpeed = runningspeed
Player.Character.Humanoid.JumpPower = 0
if round(reloadcount) == 0 then
famasreloading = false
end
wait(0.1)
if famasreloadcanceled == true then
famasreloading = false
end
end
until famasreloading == false
if famasreloadcanceled == false then
Famasmag = Famasmagsize
end
famasreloadcanceled = false
AmmonGUI.Text = (Famasmag..'/'..Famasreserve)
Player.Character.Humanoid.WalkSpeed = 16
Player.Character.Humanoid.JumpPower = 50
famasdebounce = false
end
end
end)
```````````````````````````
if you need more info, feel free to reach out to me. I am utterly stumped and this is the best place for me to go. God bless whoever can fix this bug