Best way to create a stun system for a combat system

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.

Thank you!

I never did something like this before, but here’s my idea.

  1. Have a global server sided controller for state of each player, (eg. stunned)
  2. 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
2 Likes

You could use a simple bool value, that’s how I have in mine, It’s very simple though.

stun:GetPropertyChangedSignal(“Value”):Connect(function()

if stun == true then
	-- Handle player being stunned
else
	-- Remove stun effect
end

end)

1 Like

I think I am looking for something that has much more detail with module scripts.