I have made a combat system, but I was looking for recommendations on how to control stuns and all. Like slowing the player down when punching, stun the enemy when punched, running speeds, walking speeds, jump heights and all. I want to know what is the best way to handle everything related to the users walkspeed/jumpheight.
I never did something like this before, but here’s my idea.
Have a global server sided controller for state of each player, (eg. stunned)
For each change, fire client → server → all client, each client would update the player and play needed animations
So something like:
A shared module in ReplicatedStorage
return {
state = {
default = 0,
stunned = 1,
}
}
Server side
local states: { [Player]: number } = {}
local function setState(player: Player, state: number)
states[player] = state
-- call all clients to update accordingly
end
-- when a player joins
setState(player, shared.states.default)
Client side
local stateMap = {
[shared.states.stunned] = function()
-- Stuff for stunning here (moving, animation, etc.)
end
}
-- when an event is recieved
stopOldState() -- If needed, create a function for it.
if stateMap[state] then
stateMap[state]()
end
It’s a bit too late for me to be responding, but incase anyone stumbs upon this, best thing to do is something like this:
Create a module that has the data for each type of stun
softStun = {
WalkSpeed = 0 -- Sets speed of Humanoid to 0, so they cannot move (default is 16)
JumpPower = 0 -- Disables Jumping (default is 7.2
--Optionally add JumpHeight too (default is 50)
}
Now create another module that gives the Character an attribute for each stun
local module = {}
module.CreateStun = function(Character)
Character:SetAttribute("softStun",true)
end
return module
Of course making yours more complicated than this, but there is also another stun module out there. Try researching StunVersion2.
Now on the server with a module or server script, you can handle the attributes like so
for _,Player in game.Players:GetChildren()
local Character = Player.Character
--Check if they has a stun
--Apply the properties of that stun onto the Humanoid
end