Any help on how i can add a walkspeed stun to this?

Hello! I am making a combat system for my game. I wanted to know how to add a hitstun to my combat. By hitstun i mean setting ‘hits’ (humanoid that was hit) walkspeed to 0 and then when my combo ends or when i stop attacking it goes back to their previous walkspeed. I have already tried this but i had a problem, it will work the first time if i punch them once every second they will get stunned for the time specified and go back to normal but, if i hit that humanoid twice in under a second, their walkspeed overides because everytime they get hit im setting their currently walkspeed to a variable. So if their stunned while i hit them then that walkspeed is now the stuns walkspeed since its setting to their current walkspeed everytime it hits. Is their a way to get around this and like store the walkspeed once when i punch them? but able to keep stunning them if i keep punching more than once in a quick succession (sorry for the paragraph)

TLDR: How To Stun A Humanoid With Combos

Hit Script
fist.Parent = workspace
touchConn = fist.Touched:Connect(function(hit)
if hit:isA(“BasePart”) then
if hit.Parent:FindFirstChild(“Humanoid”) then
if hit.Parent.Name ~= player.Name then
if hit.Parent.Humanoid.Health > 0 then
if not beenhit[hit.Parent] then
if count < 5 then

						damageFunctions.doDamage(hit.Parent.Humanoid,damage,player)	
						else
							damageFunctions.doDamage(hit.Parent.Humanoid,damage*1.5,player)
							
							
							local bv = Instance.new("BodyVelocity")
							bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
							bv.Velocity = (character.HumanoidRootPart.CFrame.LookVector * 70 + Vector3.new(0,20,0))
							bv.Parent = hit	
							
							spawn(function()
							wait(.3)	
							bv:Destroy()
						end)						
						end	
						
						
						hitting = hitting + 1
						
						local play = hit.Parent.Humanoid:LoadAnimation(anims[count])
						play:Play()
						spawn(function()
						while hitting > 0 do
							hitting = hitting - 0.1
							if hitting > 0 then
								if hit.Parent then	
									hit.Parent.MoveCoolDown.Value = true
										
									end
								else
									
								hit.Parent.MoveCoolDown.Value = false	
								end	
							wait(0.1)	
						end
					end)
						
					beenhit[hit.Parent] = true	
									
						if count < 5 then
						sound.Parent = hit	
						sound:Play()
						else 
							local Heavy = sound.Heavy:Clone()
							Heavy.Parent = hit
							Heavy:Play()
							spawn(function()
								wait(1)
								Heavy:Destroy()
							end)
					end		
					wait(0.2)		
					beenhit[hit.Parent] = false
					fist:Destroy()		 
					if touchConn ~= nil then touchConn:Disconnect() end
						fist:Destroy()
					end
				end
			end
		end
	end	
end)

Well start off by making this stun function on the server, the stun function it’s self could be parsed like.

local Stun = function(Humanoid)
     local Prev = Humanoid.WalkSpeed
     Humanoid.WalkSpeed = 0
     delay(TIME, function()
           Humanoid.WalkSpeed = Prev
     end)
end

Im using remote event so do i put that in the remote event connect or outside?

ima put it inside for the time being

Like so

On Server Script

Remote.OnServerEvent:Connect(function(Player, Hit, Tool)
     if Tool and Tool.Parent == Player.Character and Tool.Name == "TOOLNAMEHERE" then
          Stun(Hit)
     end
end)

On the Client

Remote:FireServer(HitPart, Tool)

The “Tool.Parent == Player.Character” is a security check for exploiters. It’s a basic check, better than nothing.

Alright ill tell you the result

It works! to a certain degree tho, its better but my original problem was that hitting more than once in a row causes them to be slowed for ever
heres a video

Gyazo Link

https://gyazo.com/2476e06e4be3559ea9327096a2c161cb

it only works if i dont hit them multiple times under the delay specified

Ah, that would be a problem, luckily we can do a debounce on the server like so.

local Debounce = {}

Remote.OnServerEvent:Connect(function(Player, Hit, Tool)
     if Tool and Tool.Parent == Player.Character and Tool.Name == "TOOLNAMEHERE" then
        if Debounce[Player] == nil then
            Debounce[Player] = true

            Stun(Hit)

            wait(0.75)
            
            Debounce[Player] = nil
        end
     end
end)

Adjust the wait time accordingly
Also game looks pretty cool

1 Like

Ooo thanks it works and also thanks, my game is coming along nicely its a MHAgame and i have & quirks so far

1 Like

Planning to choose selected testers in my discord in 2 weeks

Only problem with my game is finding things to decorate the map with lol, making quirks and things as such come more easily to me i need help with everything else

also shoot cant i just instance a body velocity to them thats really slow so they are basically stunned? lol it just clicked in my head

You could just use a body position and set the position to the players humanoid root part’s position.
WalkSpeed would work fine still.