hey there, I’m trying to create an m1 system for my game, and I want it to have a TSB kind of feel
- the camera follows the torso’s position
- the animations don’t overlap with each other
- there’s effects for specific m1s
(btw, m1s are punches/normal clicks, if you didn’t know that)
I’ve tried writing some code, but it didn’t turn out how I wanted it to
The full script
--Tool variables
local tool = script.Parent
local handle = tool:FindFirstChild("Handle")
--Player variables
local player = nil
local char = nil
local humanoid = nil
local animator = nil
tool.Equipped:Connect(function()
char = tool.Parent
player = game.Players:GetPlayerFromCharacter(char)
humanoid = char:FindFirstChild("Humanoid")
animator = humanoid:WaitForChild("Animator")
end)
--M1 system
local m1s = tool:FindFirstChild("M1s")
local currentM1 = 0
local minCycle = 1
local maxCycle = 3
local resetCycle = 1
local m1Debounce = false
local prevTrack = nil
local m1Anims = {
[1] = {
["Track"] = m1s:FindFirstChild("1")
},
[2] = {
["Track"] = m1s:FindFirstChild("2")
},
[3] = {
["Track"] = m1s:FindFirstChild("3")
}
}
local trail = handle:FindFirstChild("Trail")
local knifeWhoosh = handle:WaitForChild("KnifeWhoosh")
local function connectEvents(track)
track:GetMarkerReachedSignal("Stun"):Connect(function()
m1Debounce = true
humanoid.WalkSpeed = 8
print("stunned")
end)
track:GetMarkerReachedSignal("Unstun"):Connect(function()
m1Debounce = false
humanoid.WalkSpeed = 16
print("unstunned")
end)
track:GetMarkerReachedSignal("TrailStart"):Connect(function()
trail.Enabled = true
task.wait(0.1)
knifeWhoosh:Play()
print("trail start")
end)
track:GetMarkerReachedSignal("TrailEnd"):Connect(function()
trail.Enabled = false
print("trail ended")
end)
end
tool.Activated:Connect(function()
--Increase the currentM1 value
if m1Debounce then return end
currentM1 += 1
if (currentM1 < minCycle) or (currentM1 > maxCycle) then
currentM1 = resetCycle
prevTrack = animator:LoadAnimation(m1Anims[maxCycle]["Track"])
end
print(currentM1)
local currentTrack = animator:LoadAnimation(m1Anims[currentM1]["Track"])
connectEvents(currentTrack)
if currentM1 == 1 then
prevTrack = animator:LoadAnimation(m1Anims[maxCycle]["Track"])
else
prevTrack = animator:LoadAnimation(m1Anims[currentM1 - 1]["Track"])
end
prevTrack:Stop()
currentTrack:Play()
end)
this is the result:
this is the part where I need more attention on tho:
tool.Activated:Connect(function()
--Increase the currentM1 value
if m1Debounce then return end
currentM1 += 1
if (currentM1 < minCycle) or (currentM1 > maxCycle) then
currentM1 = resetCycle
prevTrack = animator:LoadAnimation(m1Anims[maxCycle]["Track"])
end
print(currentM1)
local currentTrack = animator:LoadAnimation(m1Anims[currentM1]["Track"])
connectEvents(currentTrack)
if currentM1 == 1 then
prevTrack = animator:LoadAnimation(m1Anims[maxCycle]["Track"])
else
prevTrack = animator:LoadAnimation(m1Anims[currentM1 - 1]["Track"])
end
prevTrack:Stop()
currentTrack:Play()
end)
I thought that saving the previous track and stopping it before playing the new one would remove the effect of animations overlapping each other, but it still didn’t work
if anybody has any solutions, please help me out! thanks ![]()