Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

why this combo counter not works? i checked click detact is not problem.

Asked by 2 years ago
Edited 2 years ago
    click.OnServerEvent:Connect(function(plr,attack)                    --Sword
        local combo = 1
        if tick()-last > 2 or combo <= 4 then
            combo = 1
        else
            if combo == 1 then  
            end
            if combo == 2 then
            end
            if combo == 3 then
            end
            if combo == 4 then
            end
            combo = combo + 1
            last = tick()
            print(combo)
        end
    end)
0
that script is not prints combo chc5282 0 — 2y
0
Try to show client script. It maybe because this is don't triggers. Also you need put print not in the "else" AgentViteC 58 — 2y
0
local mouse = player:GetMouse() mouse.Button1Down:Connect(function() click:FireServer() end) chc5282 0 — 2y
0
ops i need to change combo = tick() to last = tick() chc5282 0 — 2y
0
not works chc5282 0 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago

I'd assume that's because you are setting the variable to 1 every time the event is fired, so try using a table or IntValue to store individual player's combo counter

local comboCounter = {}
local lastTick = {}

game.Players.PlayerAdded:Connect(function(player)
    comboCounter[player] = 0
    lastTick[player] = 0
end)

click.OnServerEvent:Connect(function(player)
    if tick() - lastTick[player] > 2 or comboCounter[player] <= 4 then
        comboCounter[player] = 1
    else
        if comboCounter[player] == 1 then  
        end
        if comboCounter[player] == 2 then
        end
        if comboCounter[player] == 3 then
        end
        if comboCounter[player] == 4 then
        end

        comboCounter[player] =+ 1
        lastTick[player] = tick()
        print(comboCounter[player])
    end
end)
Ad

Answer this question