Punch script being spammable at low fps

My punch script is spammable at 30 FPS. I have no idea why this is but here’s my code:

UIS.InputBegan:Connect(function(Input, gameprocessed)
	if gameprocessed then return end
        if Input.UserInputType == Enum.UserInputType.MouseButton1 then
		if not equipped then return end
		if M1CD then return end
		local isStun = checkState:InvokeServer("Stun")
		local isBlocking = checkState:InvokeServer("Blocking")
		if isStun then return end 
		if isBlocking then return end

		M1CD = true

		currTime = tick()

		local passedTime = currTime - prevTime
		if passedTime < 1.5 then
			count = count + 1
			if count > 5 then
				count = 1
			end
		else
			count = 1
		end

		Combat:FireServer("Combo","None",count)

		task.wait(0.25)

		if char:FindFirstChild("Hitstun") then 
			M1CD = false
			return 
		end

		local Hitbox = Instance.new("Part",plr.Character)
		Hitbox.Name = "PunchHitbox"
		Hitbox.Massless = true
		Hitbox.CanCollide = false
		Hitbox.Size = Vector3.new(3.5,4,4)
		Hitbox.Transparency = 1
		Hitbox.BrickColor = BrickColor.new("Really red")
		Hitbox.Material = Enum.Material.Neon
		Hitbox.CFrame = char.HumanoidRootPart.CFrame
		game.Debris:AddItem(Hitbox,0.12)

		local HitBoxWeld = Instance.new("Weld",char.HumanoidRootPart)
		HitBoxWeld.Part0 = char.HumanoidRootPart
		HitBoxWeld.Part1 = Hitbox
		HitBoxWeld.C0 = CFrame.new(0,0,-2.3)

		local HitFolder = Instance.new("Folder",Hitbox)
		HitFolder.Name = "HitFolder"

		Hitbox.Touched:connect(function(Part)
			if Part.Parent:FindFirstChild("Humanoid") and HitFolder:FindFirstChild(Part.Parent.Name) == nil and Part.Name == "Torso" and char:FindFirstChild("Humanoid") then
				local GodBodyValue = Instance.new("ObjectValue", HitFolder)
				GodBodyValue.Name = Part.Parent.Name
				game.Debris:AddItem(GodBodyValue,.12)
				Combat:FireServer("M1",Part.Parent,count)
			end
		end)
	end
end)

Example:

Try changing tick() to os.clock() instead as it’s more accurate. If that doesn’t work, use the ol’ debounce method instead.

Just use the :GetRealPhysicsFPS() function to check the user’s fps.

if game.Workspace:GetRealPhysicsFPS() <= 30 then
    cooldown = 3
end
1 Like

Tried this, still produced the same result.

If you don’t mind explaining, what is the old debounce method?

It’s

local debounce = false

(probably)

It’s essentially putting in place a cooldown with a variable and wait. For example:

local debounce = false

if not debounce then
	debouce = true
	 -- Code to execute
	
	task.wait(COOLDOWN)
	debounce = false
end

I already have that implemented in the script as

M1CD = true

Roblox is probably suspending your thread to wait for the server response from InvokeServer.
In that time, a user can input again.

Move M1CD = true before the InvokeServer calls, and also please give M1CD a more descriptive name.

1 Like

Ok, will do. I forgot that remote functions can halt threads.