#Help With M1 Combo Script

1 messages · Page 1 of 1 (latest)

sturdy walrus
#

I am trying to make a basic weapon attack script that has a combo, so that if you M1 once, it does an attack, if you M1 again within 0.25 seconds, it does a different attack and so on, but I am not good at logic so pls help.

#
local anim2 = script.Animation2
local anim3 = script.Animation3

script.Parent.M1Event.OnServerEvent:Connect(function(player)
    local animator = player.Character.Humanoid.Animator
    local slashstage = 0
    slashstage += 1
    if slashstage == 1 then
        local animtrack1 = animator:LoadAnimation(anim1)
        animtrack1:Play()
        animtrack1.Ended:Wait()
        task.wait(0.25)
        slashstage = 0
    elseif slashstage == 2 then
        local animtrack2 = animator:LoadAnimation(anim2)
        animtrack2:Play()
        animtrack2.Ended:Wait()
        task.wait(0.25)
        slashstage = 0
    elseif slashstage == 3 then
        local animtrack3 = animator:LoadAnimation(anim3)
        animtrack3:Play()
        animtrack3.Ended:Wait()
        task.wait(0.25)
        slashstage = 0
    end
end)
empty elm
#

@sturdy walrus

#

i suggest you watch it completely but the last part (21:25) is where this yt mentions the thing u wanna do

#

DISCORD 📜
Join my Discord Community if you want scripting help, participate in events/challenges, and make friends!
https://discord.gg/WC6kPu5W5P

MEMBERSHIPS 🎁
Get Access To My Scripts + More Perks By Becoming a Channel Member! 👇
https://www.youtube.com/@BrawlDevRBLX/join

ADVANCED ROBLOX SCRIPTING SERIES 🔴
https://www.youtube.com/p...

▶ Play video
sick spruce
# sturdy walrus ```local anim1 = script.Animation1 local anim2 = script.Animation2 local anim3 =...

Yea you're kinda doing too much here. You can use the DateTime lib to keep track of the last time the player clicked M1.

If you don't already know, there's this thing called unix timestamp that basically counts the number of seconds that has passed since January 1, 1970. Programs use this for precise time logic and stuff, so you could definitely use it here.

DateTime.now() basically just gives you the amount of seconds since jan 1, 1970 until the moment you called the command. In other words, you could do something like this...

local lastPunchDateTimeInMillis = 0
local punchStreak = 0

local function punch()
    local currentDateTime = DateTime.now()
    local currentDateTimeInMillis = currentDateTime:ToUnixTimestampMillis()
    local timeElapsed = currentDateTimeInMillis - lastPunchDateTimeInMillis
    
    if timeElapsed <= 250 then
        punchStreak += 1
    else
        punchStreak = 1
    end

    lastPunchDateTimeInMillis = currentDateTimeInMillis

    if punchStreak == 1 -- first punch
    elseif punchStreak == 2 -- second punch
    -- etc
end

Did not test this logic so you might need to tweak it a bit, but essentially that's what you need to do.

#

I think os.clock() does the same but I'm not sure. Google about that as well

sturdy walrus
#

Thx