[IMPORTANT!] I need help with this problem

I need help with some stuff that doesn’t make sense.

I don’t know why this happens:

local db = false

Combat.OnServerEvent:Connect(function(Player, mouseInput)
	if Player.Character:FindFirstChild("Humanoid") then
		if Start - tick() <= .3 then combo = combo + 1 end
		if combo == 1 or combo == 3 then
			if combo == 1 and not db then
				db = true
				print(combo)
				wait(punchTime)
				db = false
			elseif combo == 3 and not db then
				db = true
				print(combo)
				wait(punchTime)
				db = false
			end
		elseif combo == 2 or combo == 4 then
			if combo == 2 and not db then
				db = true
				print(combo)
				wait(punchTime)
				db = false
			elseif combo == 4 and not db then
				db = true
				print(combo)
				wait(punchTime)
				db = false
			end
		end
	end
end)

It should print: 1, 2, 3, 4, but when spammed it prints random numbers, and it only happens when I add a denounce any ideas why?

Also, the code I showed, is not the full code I just showed what was needed.

1 Like

A bit strange the way you detect the combo but try this one:

   if Player.Character:FindFirstChild("Humanoid") then
	if Start - tick() <= .3 then combo = combo + 1 end  ‐-----i don't think you will need this try removing it
     	if combo == 1  and not db then
		
				db = true
				print(combo)
				wait(punchTime)
				db = false
                           combo = 2   
   			elseif combo == 2 and not db then
				db = true
				print(combo)
				wait(punchTime)
				db = false
                           combo = 3
		elseif combo == 3 and not db
				db = true
				print(combo)
				wait(punchTime)
				db = false
                            combo = 4
			elseif combo == 4 and not db then
				db = true
				print(combo)
				wait(punchTime)
				db = false
                         combo = 1
		end
	end
end)
3 Likes

Try some player specific variables:

local UserData = {}
local PunchTime = .125


game:GetService("Players").PlayerRemoving:Connect(function(Player) UserData[Player.UserId] = nil end)
Combat.OnServerEvent:Connect(function(Player, mouseInput)
	local Data = UserData[Player.UserId]
	local DBValue = false
	local ComboIndex = 0
	local ComboTimestamp = tick()
	if Data ~= nil then
		DBValue = Data[1]
		ComboIndex = Data[2]
		ComboTimestamp = Data[3]
	else
		UserData[Player.UserId] = {DBValue, ComboIndex, ComboTimestamp}
	end
	if DBValue then return end -- Player Attacks are on cooldown, stop function execution (return)
	if Player.Character == nil then return end -- Character is nil, return
	if Player.Character:FindFirstChild("Humanoid") == nil then return end
	UserData[Player.UserId][1] = true -- Set DB
	if (tick() - ComboTimestamp) <= .3 then
		ComboIndex += 1
	else
		ComboIndex = 1 -- Attacks too far apart, reset combo to 1
	end
	if ComboIndex > 4 then
		ComboIndex = 1
	end
	UserData[Player.UserId][2] = ComboIndex -- Update ComboIndex
	if ComboIndex == 1 or ComboIndex == 3 then
		if ComboIndex == 1 then
			print(ComboIndex)
			wait(PunchTime)
		else -- ComboIndex is 3
			print(ComboIndex)
			wait(PunchTime)
		end
		UserData[Player.UserId][3] = tick() -- Set ComboTimestamp
		UserData[Player.UserId][1] = false -- Set DB
		return
	elseif ComboIndex == 2 or ComboIndex == 4 then
		if ComboIndex == 2 then
			print(ComboIndex)
			wait(PunchTime)
		else -- ComboIndex is 4
			print(ComboIndex)
			wait(PunchTime)
		end
		UserData[Player.UserId][3] = tick() -- Set ComboTimestamp
		UserData[Player.UserId][1] = false -- Set DB
		return
	end
end)
2 Likes

I’ll try it out and see it workey :sunglasses: thanks for actually responding and taking time much love.

Wait what is DB meant to be?
like a table or something

local DB = {}
or
local DB;

and I seem to get this problem:

I updated the script (4th edit)

(DB = Old name for the UserData variable that I forgot to change)

Ok so you can probably get it to work with the code you sent but I tested the guy that replied first and it works pretty well, and since what he uses is really similar to my original code I can understand it better
but thanks anyways.

And I will probably test yours either way

Np, if you do not understand it well it would be hard to iron out all the little bugs that come as a result of not being able to test it with your studio environment. I’m not sure how your original script or the reply similar to it would work with multiple players though.

For this, a switch module would be useful. Switch. A SwitchCase Simulation

Yes now I fully understand how the script itself works so I’ll use part of your solution as you said I don’t know if mine will work with lots of players.

ALSO TO ANYONE READING THIS THREAD PLEASE DO NOT ASK ME TO GIVE YOU THE FULL SCRIPT, STOP SKIDDING AND MAKE YOUR OWN

I just updated the script with a final version that should work with multiple players

image

1 Like

Can you pm me your discord so we could talk about something?

1 Like