Remote event fires twice inside a while loop for some reason

ya it’s still 0.075, can this be a problem on your end? try publish the game and read the dev output thingy?

publishing the game and testing it in-game still has the issue

this is really weird, and i honestly don’t know how to fix this and i assume you don’t know how to either

<_< this is so annoying

can i see a screen shot of the devlog output thing there could be something im missing??

okay, now this is EXTREMELY weird

the while loop no longer runs twice in one go, but the anti cheat issue still stays

i’m honestly gonna ask GPT for a bit of help on this but if you’ve got any ideas then do not hesitate to tell

ya I don’t know what to think about this and all at this point, but if chatGPT fixes it please tell what was wrong or i may not be able to sleep tonight just thinking about this lol

ohhhhh wait a second

i see the issue now

didn’t even get this from GPT

the module script function gets called inside the local script, that local script checks for the state of the gun (so client sided anticheat is there)

the module script IGNORES that because well, there’s no anticheat in there and automatic shooting is handled in there

i’ve got a fix in mind, i’ll let you know if it works or not

nvm my genius fix didn’t work i’m just gonna ask gpt :skull:

nvm man gpt didn’t fix anything

ugh i’ll have to brainstorm this

Hi, when does the RemoteEvent starts to fire twice? Is it when you equip it or after using the weapon for a while (equipping it and unequipping it)

hi!

it’s hard to explain but

the anti-cheat is only run inside the local script

but then it’s never checked on the module script, honestly idk what is happening idk how to explain it

i could send you the code privately if you want to investigate it deeper

D:

okay i fixed it

i got a revelation while being in bed and it turns out i have the IQ of a carrot

anyway, the changes i’ve made were:
new automatic function (server-side):

AUTOMATIC = function(origin: Part, player: Player, hitPos: Mouse, weapon: Tool)
		local FIRERATE = gunInfo[weapon.Name]["FIRERATE"]
		
		weapon.IsHolding.Value = true
		local updateConnection
		
		updateConnection = updateHitPosEvent.OnServerEvent:Connect(function(updatePlayer, newHitPos)
			if updatePlayer == player then
				hitPos = newHitPos
			end
		end)
		
		while weapon.IsHolding.Value do
			if weapon.Bullets.Value < 1 then
				weapon.Shooting.Value = false
				weapon.IsHolding.Value = false
				updateConnection:Disconnect()
			end
			
			Raycasting(origin, player, hitPos, weapon)
			weapon.Bullets.Value -= 1
			weapon.FlashPart.ShootSound:Play()
			task.wait(FIRERATE)
		end
		-- these 3 here are probably unnecessary but who cares!
		weapon.IsHolding.Value = false
		weapon.Shooting.Value = false
		updateConnection:Disconnect()
	end,

automatic function (client-side)

AUTOMATIC = function(weapon: Tool, mouse: Mouse, shootAnim: Animation)
		local FIRERATE = gunStats[weapon.Name]["FIRERATE"]

		local buttonUpConnection
		shooting = true

		buttonUpConnection = mouse.Button1Up:Connect(function()
			disableIsHoldingEvent:FireServer()
			shooting = false
			buttonUpConnection:Disconnect()
		end)
		
		shootEvent:FireServer(mouse.Hit.Position)
		
		while shooting do
			if weapon.Bullets.Value < 1 then disableIsHoldingEvent:FireServer()break end
			shootAnim:Play()
			updateHitPosEvent:FireServer(mouse.Hit.Position)
			ApplyRecoil(weapon)
			task.wait(FIRERATE)
		end
		
		shooting = false
	end,

i can’t be bothered to explain what the problem was

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.