I’ve got a remote event, and that remote event is meant to shoot gun (yay!)
but that remote event fires TWICE at the same time for some reason (pensive)
instead of bumping my previous post, i’m gonna ask why this remote event fires twice, or well, everything in the while loop runs twice for some reason
AUTOMATIC = function(weapon: Tool, mouse: Mouse, shootAnim: Animation)
local FIRERATE = gunStats[weapon.Name]["FIRERATE"]
shooting = true
local buttonUpConnection
buttonUpConnection = mouse.Button1Up:Connect(function()
disableIsHoldingEvent:FireServer()
shooting = false
buttonUpConnection:Disconnect()
end)
while shooting do
if weapon.Bullets.Value < 1 then
disableIsHoldingEvent:FireServer()
shooting = false
break
end
shootEvent:FireServer(mouse.Hit.Position)
shootAnim:Play()
print("i have fired remote event too many times because i have stupid lol!") -- this will print twice at once, which means everything in here runs twice for some reason
ApplyRecoil(weapon)
task.wait(FIRERATE)
end
end
uh i call it slightly below the table of functions
table of functions in a table of functions, ironic i know
function shootingModule.Shoot(weapon: Tool, player: Player)
local char = player.Character
local humanoid = char:WaitForChild("Humanoid")
local mouse = player:GetMouse()
local animator = humanoid:FindFirstChildOfClass("Animator")
local shoot = weapon:WaitForChild("Shoot")
local shootAnim = animator:LoadAnimation(shoot)
shootFunctions[weapon.GunType.Value](weapon, mouse, shootAnim) -- Indexing right here!!!
end
everything is in a module script, and that module script gets called from a local script:
char.ChildAdded:Connect(function(child)
if not child:IsA("Tool") then return end
weapon = child
if weapon.WeaponType.Value == "GUN" then
local Shooting = weapon:WaitForChild("Shooting")
local Reloading = weapon:WaitForChild("Reloading")
local Bullets = weapon:WaitForChild("Bullets")
local Equipping = weapon:WaitForChild("Equipping")
local Shoot = weapon:WaitForChild("Shoot")
local FIRERATE = gunStats[weapon.Name]["FIRERATE"]
downConnection = mouse.Button1Down:Connect(function()
if Shooting.Value then return end
if Reloading.Value then return end
if Bullets.Value < 1 then return end
if Equipping.Value then return end
shootingModule.Shoot(weapon, plr)
end)
end
end)
and yes i do, but only whenever the tool gets unequipped
char.ChildAdded:Connect(function(child)
if not child:IsA("Tool") then return end
weapon = child
if weapon.WeaponType.Value == "GUN" then
local Shooting = weapon:WaitForChild("Shooting")
local Reloading = weapon:WaitForChild("Reloading")
local Bullets = weapon:WaitForChild("Bullets")
local Equipping = weapon:WaitForChild("Equipping")
local Shoot = weapon:WaitForChild("Shoot")
local FIRERATE = gunStats[weapon.Name]["FIRERATE"]
downConnection = mouse.Button1Down:Connect(function()
if Shooting.Value then return end
if Reloading.Value then return end
if Bullets.Value < 1 then return end
if Equipping.Value then return end
shootingModule.Shoot(weapon, plr)
end)
end
end)
char.ChildRemoved:Connect(function(child)
if not child:IsA("Tool") then return end
if downConnection then
downConnection:Disconnect()
end
weapon = nil
shooting = false
end)
No idea why its firing twice but I made a debounce system to prevent it from doing that, try implementing something like this to the function above:
local Debounces = {}
function Shoot(player)
if not Debounces[player.Name] then
Debounces[player.Name] = true
end
if Debounces[player.Name] == true then
Debounces[player.Name] = false
print("EEE")
task.wait(10)
Debounces[player.Name] = true
end
end
local Debounces = {}
function shootingModule.Shoot(weapon: Tool, player: Player)
if not Debounces[player.Name] then
Debounces[player.Name] = true
end
if Debounces[player.Name] == true then
Debounces[player.Name] = false
local char = player.Character
local humanoid = char:WaitForChild("Humanoid")
local mouse = player:GetMouse()
local animator = humanoid:FindFirstChildOfClass("Animator")
local shoot = weapon:WaitForChild("Shoot")
local shootAnim = animator:LoadAnimation(shoot)
shootFunctions[weapon.GunType.Value](weapon, mouse, shootAnim)
task.wait(gunStats[weapon.Name]["FIRERATE"])
Debounces[player.Name] = true
end
end
Small issue i can see and that’s that if they player swaps to a different gun while on cooldown (if they can) the gun will be on cooldown for the old guns fire rate
Is it possible if you could make a new place dump all the relevant items into it and uncopylock it then send the link? as I have genuinely no idea how to help other wise (unless you also don’t like sharing your scripts lol)
i just removed all the animations as i wasn’t the owner of them so they wouldn’t play and end up breaking also turned up the fire rate to make it move obvious if there was an issue and I’m rarely getting the message printing 2 times
oh I see I increased the max bullets so I could test for longer and it triggered the anitcheat, I didn’t notice you have something setup to detect that