How do I make this stun system?

I’m attempting to make a game that’s combo based so I need to make an efficient stun system.
The system should be able to take in multiple stun requests while keeping the walkspeed of the stun that is more important (you’ll understand with the example given below)

ex:
a player gets perfect blocked then hit I need the walkspeed to remain 0 since the player got perfect blocked and not change the walkspeed to 12 for example because the player got hit, I don’t have an idea of where to start I made one before but it didn’t do well since there’s a delay between the server and the client in game because of the ping if anyone knows a way to do this without it taking that much time or instancing alot of items it would be amazing.

any help or ideas are appreciated, have a great day.

3 Likes

Use RenderStepped on the client. I know it sounds stupid as it is exploitable, but at least it’s safer than using ChildAdded as an exploiter could just change their walkspeed back to the default one and nothing would change it back to the stunned-speed.

1 Like

Thank you. but how would the controlling script know that the player is stunned and thus preventing him from blocking?

Well it really is your choice. What I do usually is to check if a player has an instance with a specific classname (I call it the “S-Instance”, long term “Stun Instance”) inside of a debounce folder located in the character. To check it on the server you can use ChildAdded, and if the child has a specific classname then make the player stop blocking.

1 Like

Use signals and tables.


local punchEvent = ...

local StunnedPlayers = {}

punchEvent.OnServerEvent:Connect(function(player, enemyName) -- hitbox detection on the client is faster.
   if StunnedPlayers[player] then -- prevent player from punching (maybe stop movement here?)
      return
   end
   -- magnitude check here etc
   -- do damange and add player to stunned table
   StunnedPlayers[enemy] = true
   -- remove player from stunned table after x seconds
   delay(x, function() -- I personally don't recommend using delay.
       StunnedPlayers[enemy] = nil
   end)
end)

Instances are cool but tables are faster and you can make use of signals to check whenever someone is stunned or not, signals are basically custom events:

OnPlayerStunned:Connect(function(stunnedPlayer, value) -- ofc you can send custom arguments as well.
    local character = stunnedPlayer.Character
    if value then -- player is stunned
       character.HumanoidRootPart.Anchored = true -- just an example.
    else -- player is not stunned
       character.HumanoidRootPart.Anchored = false -- just an example.
    end
end)

I dont quite understand this part

OnPlayerStunned:Connect(function(stunnedPlayer, value) -- ofc you can send custom arguments as well.
    local character = stunnedPlayer.Character
    if value then -- player is stunned
       character.HumanoidRootPart.Anchored = true -- just an example.
    else -- player is not stunned
       character.HumanoidRootPart.Anchored = false -- just an example.
    end
end)

where did you get the “OnPlayerStunned” event can you explain it please?

Introducing Signal Class 2: A new way to create custom events - Community Tutorials - DevForum | Roblox

2 Likes

In my script I just used a simple spawnfunction.

spawn(function()
Humanoid.WalkSpeed = 0
wait(2)
Humanoid.WalkSpeed = 16
end)

If you want a player to not be able to punch while stunned add a boolvalue into them. Then in the local script for the punch do this

if BoolValue then return end

This would mean that player wont be able to punch depending on how long you add the BoolValue into the player.

I hope this helps!

1 Like

You can try out my stun handler.
All you need to do is require the module and pass a humanoid object and the duration you want the stun to last for to the function.

You can customise it further to give different walkspeeds instead of reducing it to 0 like you mentioned in the post.