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