Trying to track if the player is punching or not but it seems to either go slow or go too fast
https://gyazo.com/307c39c440608676de9edd34611d4d24
The Script Itself

Trying to track if the player is punching or not but it seems to either go slow or go too fast
https://gyazo.com/307c39c440608676de9edd34611d4d24
The Script Itself

If you use spawn, everything inside it will execute in a separate thread, which means while one thread is setting the value to false, the other one sets it to true. Is this wrapped inside some loop?
Full code please.
script.Parent.RemoteEvent.OnServerEvent:Connect(function(player)
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:FindFirstChild(“Humanoid”)
local Tool = script.Parent
local bv = Instance.new("BodyVelocity")
bv.Name = "Lockon"
bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
local bv2 = Instance.new("BodyVelocity")
bv2.Name = "Lockon"
bv2.MaxForce = Vector3.new(math.huge,0,math.huge)
local LastTargetPosition = char.HumanoidRootPart.CFrame
local push2 = Instance.new("BodyVelocity")
push2.Name = "push2"
local stats1 = char:FindFirstChild("Stats")
local Config = Tool.Config
local combo = stats1.Combo
local Strength = stats1.Strength
local range = Config.Range.Value
local dmg = Config.Dmg.Value
local reset = 1.1
local run = script.Parent.Parent.Stats.Run
if run.Value == true then
run.Value = false
hum.WalkSpeed = 16
local ActiveTracks = hum:GetPlayingAnimationTracks()
for _,v in pairs(ActiveTracks) do
if v.Name == "Run" then
v:Stop()
end
end
end
if tick() - last >= reset or combo.Value == 5 then
combo.Value = 0
end
last = tick()
combo.Value = combo.Value + 1
local m1 = script.Parent.Parent.Stats.M1
spawn(function()
m1.Value = true
task.wait(3.5)
m1.Value = false
end)
local first = hum:LoadAnimation(Tool.Anims.attack1)
local second = hum:LoadAnimation(Tool.Anims.attack2)
local third = hum:LoadAnimation(Tool.Anims.attack3)
local fourth = hum:LoadAnimation(Tool.Anims.attack4)
local fifth = hum:LoadAnimation(Tool.Anims.attack5)
if combo.Value == 1 then
first:Play()
first:AdjustSpeed(1.3)
char.Torso.SwingFist:Play()
char.Torso.SwingFist.Pitch = 1.15 * (math.random(90, 110) / 100)
elseif combo.Value == 2 then
second:Play()
second:AdjustSpeed(1.3)
char.Torso.SwingFist:Play()
char.Torso.SwingFist.Pitch = 1.15 * (math.random(90, 110) / 100)
elseif combo.Value == 3 then
third:Play()
third:AdjustSpeed(1.3)
char.Torso.SwingFist:Play()
char.Torso.SwingFist.Pitch = 1.15 * (math.random(90, 110) / 100)
elseif combo.Value == 4 then
fourth:Play()
fourth:AdjustSpeed(1.3)
char.Torso.SwingFist:Play()
char.Torso.SwingFist.Pitch = 1.15 * (math.random(90, 110) / 100)
elseif combo.Value == 5 then
fifth:Play()
fifth:AdjustSpeed(1.6)
char.Torso.SwingFist:Play()
char.Torso.SwingFist.Pitch = 0.8 * (math.random(70, 90) / 70)
end
wait(0.2)
local Region = Region3.new(char.HumanoidRootPart.CFrame*CFrame.new(0,0,-4.8).p - Vector3.new(4,2.5,3),char.HumanoidRootPart.CFrame*CFrame.new(0,0,-4.8).p + Vector3.new(4,2.5,3))
local RTable = workspace:FindPartsInRegion3(Region, nil, 20)
for i,v in pairs(RTable) do
if v.Parent:findFirstChild("Humanoid") and v.Parent:findFirstChild("Deb") == nil and v.Parent ~= char then
local m = v.Parent
local d = (m.HumanoidRootPart.Position - char.HumanoidRootPart.Position).unit
local Deb = Instance.new("BoolValue", v.Parent)
Deb.Name = "Deb"
game.Debris:AddItem(Deb,0.2)
local blocking = m:FindFirstChild("Stats").Blocking
local yes = (char.HumanoidRootPart.Position - m.HumanoidRootPart.Position).Unit
local look = m.HumanoidRootPart.CFrame.LookVector
local final = yes:Dot(look)
if final > .5 then
Behind = false
else
Behind = true
end
if blocking.Value == true then
if Behind == true then
blocking.Value = false
local ActiveTracks = m.Humanoid:GetPlayingAnimationTracks()
for _,v in pairs(ActiveTracks) do
if v.Name == "Blocking" then
v:Stop()
end
end
end
end
if blocking.Value == true then
if combo.Value == 5 then
BlockBreakModule.Break(m)
Module.Stun(m.Humanoid, 1.5)
return end
m.Humanoid:LoadAnimation(m.Anims.Blocked):Play()
m.Torso.Blockd:Emit(1)
m.Torso.block:Play()
m.Humanoid:TakeDamage(0.2)
return end
if combo.Value == 5 then
if run.Value == true then
run.Value = false
hum.WalkSpeed = 16
local ActiveTracks = hum:GetPlayingAnimationTracks()
for _,v in pairs(ActiveTracks) do
if v.Name == "Run" then
v:Stop()
end
end
end
m.Humanoid:TakeDamage(8)
m.Torso.Hit1:Emit(1)
m.Torso.Hit2:Emit(1)
m.Torso.Punched3:Play()
local ShockVFX = game.ReplicatedStorage.Shockfx:Clone()
ShockVFX.Parent = m.Torso
local w = Instance.new("Weld")
w.Part0 = m.Torso
w.Part1 = ShockVFX.Shock
w.Parent = m.Torso
local tween = ts:Create(ShockVFX.Shock, TweenInfo.new(1, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out), {Size = Vector3.new(27.981, 27.981, 27.981)})
local tween2 = ts:Create(ShockVFX.Shock, TweenInfo.new(1, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out), {Transparency = 1})
tween:Play()
tween2:Play()
push2.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
push2.Velocity = char.HumanoidRootPart.CFrame.lookVector*75 + char.HumanoidRootPart.CFrame.UpVector*65
push2.Parent = m.HumanoidRootPart
Module.Stun(m.Humanoid, 1.3)
Debris:AddItem(push2, 0.3)
Debris:AddItem(ShockVFX, 1)
return end
m.Torso.Hit1:Emit(1)
m.Torso.Hit2:Emit(1)
m.Humanoid:TakeDamage(4.2)
Module.Stun(m.Humanoid, 1)
if run.Value == true then
run.Value = false
hum.WalkSpeed = 16
local ActiveTracks = hum:GetPlayingAnimationTracks()
for _,v in pairs(ActiveTracks) do
if v.Name == "Run" then
v:Stop()
end
end
end
bv.velocity = (d * 10) -- was 5
bv2.velocity = (d * 10) -- was 5
bv2.Parent = m.HumanoidRootPart
bv.Parent = char.HumanoidRootPart
if combo.Value == 1 then
m.Torso.Punched1:Play()
m.Torso.Punched1.Pitch = 1.15 * (math.random(90, 110) / 100)
m.Humanoid:LoadAnimation(m.Anims.RightStun):Play()
elseif combo.Value == 2 then
m.Torso.Punched1:Play()
m.Torso.Punched1.Pitch = 1.15 * (math.random(90, 110) / 100)
m.Humanoid:LoadAnimation(m.Anims.LeftStun):Play()
elseif combo.Value == 3 then
m.Torso.Punched1:Play()
m.Torso.Punched1.Pitch = 1.15 * (math.random(90, 110) / 100)
m.Humanoid:LoadAnimation(m.Anims.RightStun):Play()
elseif combo.Value == 4 then
m.Torso.Punched2:Play()
m.Humanoid:LoadAnimation(m.Anims.ChestStun):Play()
end
end
game.Debris:AddItem(bv, .2)
game.Debris:AddItem(bv2, .2)
end
end)
Without spawn it delays the whole script.
I don’t see why it’s doing that, for some reason this script might be duplicated or there are multiple executing at once?
This is the local script
mouse.Button1Down:Connect(function()
if cd == true or blocking.Value == true or char:GetAttribute(“Stunned”) == true or char:FindFirstChildOfClass(“Tool”) then return end
cd = true
script.RemoteEvent:FireServer("Combat")
wait(0.45)
cd = false
if combo.Value == 5 then
spawn(function()
hum.WalkSpeed = 10
task.wait(0.3)
hum.WalkSpeed = 16
end)
cd = true
task.wait(1)
cd = false
end
end)
Try wrapping it in an if statement
spawn(function()
if m1.Value then
m1.Value = true
task.wait(3.5)
m1.Value = false
end
end)
small nitpick, use task.spawn instead of spawn
Without it being true it wont work which it needs to be
I think the problem might be that for some reason when the .Button1Down event is fired it’s firing the Remote Event too fast, which may be causing the issue.
This condition:
if cd == true or blocking.Value == true or char:GetAttribute(“Stunned”) == true or char:FindFirstChildOfClass(“Tool”) then return end
It seems not to be evaluated as true, so it keeps firing the event.
It seems to run only when i click though?
I think instead of waiting 3.5 seconds like you’re doing, set it to false when the last animation plays (based on this combo system you have)
Nvm i just made a new value each time u m1 and to check if they’re m1ing just use char.Stats:FindFirstChild(“Value”)