I want to achieve a combat script the player clicks their left mouse which will initiate a full combo and each the player clicks their mouse the animations are played
Lets say the player clicks their mouse once it would play the first animation then if they click their mouse a second and third time within a second of the first animation being played the second and third animation would play
I simply want to know how i should tackle this should i use loops or something else?
This is what i have so far btw script is in StarterCharacterScripts
local RightPunch = script:WaitForChild("Right Punch")
local LeftPunch = script:WaitForChild("Left Punch")
local Extender = script:WaitForChild("Extender")
local Knee = script:WaitForChild("Knee")
local Kick = script:WaitForChild("Kick")
local Char = script.Parent
local Humanoid = Char:WaitForChild("Humanoid")
local UIS = game:GetService("UserInputService")
local AnimationOn = false
local LoadAnimation
local CurrentAnimID
UIS.InputBegan:Connect(function(input, gpe)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
AnimationOn = true
CurrentAnimID = RightPunch.AnimationId
LoadAnimation = Humanoid:LoadAnimation(RightPunch)
LoadAnimation:Play()
end
end)
3 Likes
You could log the current time whenever the player clicks, and compare times to the next time the player clicked. e.g
local lastTimeClicked = os.clock()
-- clicked
local currentTime = os.clock()
if (lastTimeClicked - currentTime < 0.5) then
-- do combo
end
lastTimeClicked = currentTime
The example code above is just purely an example, you could definitely use tables and such to make it much cleaner
EDIT: forgot to assign lastTimeClicked
to the current time, added that back in, as it’s quite important
2 Likes
To also help you organization wise you could create a table and have all the animations for punching in there and use table.find
for each attack, you don’t even need to use table.find but putting it in a table would prove useful
1 Like
One more question how do i detect the amount of mouse has been clicked to continue the combo
Would i use something like this?
if MouseClicked == 1 then
– Would play animation here and sound
end
if MouseClicked == 2 then
– would play animation here and sound
end
and so on MouseClicked is variable i made
Mouse clicked is a variable i made
You could use debounce for it.
You could do something like this:
local currentComboClicks = 0
local maxClicks = 4
local lastTimeClicked = os.clock()
local Combos = {
[1] = { -- "1" = number of clicks
-- put your stuff in here, like animation id and stuff
}
}
-- clicked
local currentTime = os.clock()
if (currentTime - lastTimeClicked < 0.5) then
currentComboClicks += 1
local comboData = Combos[currentComboClicks]
-- do combo
if (currentComboClicks == maxClicks) then
currentComboClicks = 0
end
end
lastTimeClicked = currentTime
5 Likes