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.
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)
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)
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.
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.
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