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.
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.
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.
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)
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?
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.