Help with my StatusEffect module

I want to be able to store keys in a table that have data of the speed the player should move at.

local function GetHighestPriorityState(states)
	local highestPriorityState = nil
	local highestPriority = 0

	for stateName, data in pairs(states) do
		if data.Priority and data.Priority > highestPriority then
			highestPriority = data.Priority
			highestPriorityState = data
		end
	end

	return highestPriorityState
end

ActiveStates = {
		SlowNumber1 = {Speed = 5, JumpPower = 30, Priority = 4}
		SlowNumber2 = {Speed = 1, JumpPower = 60, Priority = 5}
	}

Along with that I would want to add the player’s currently used moves, added Stun Effects which would return true if a table is indexed with something:

AddedStunEffects = {
		StunNumber1 = {Speed = 5, JumpPower = 30, Priority = 4}
		SlowNumber5 = {Speed = 1, JumpPower = 60, Priority = 5}
	}

	-- Returns true if it finds anything in that table, immobilizing the player to do any more moves

and this is the current structure I’m stuck with:

function StatusEffects.Initialize(player: Player)
	local character = player.Character or player.CharacterAdded:Wait()
	if not CharacterStates[character] then
		CharacterStates[character] = {
			Humanoid = character:WaitForChild("Humanoid"),
			ActiveStates = {},
			CurrentSpeed = Config.BaseSpeed,
			CurrentJump = Config.BaseJump
		}		
		if IsServer then
			Transmit:FireTo(player, "Initialize")
		end
	end
end

I need help with structuring this in a manner that will allow me to add states, check for indexed tables and returning booleans.

function StatusEffects.AddState(character: Model, stateName: string, data: {any})
	local stateInfo = CharacterStates[character]
	if not stateInfo then return end
	
	stateInfo.ActiveStates[stateName] = data
	StatusEffects.Update(character)
	
	if data.Dura and data.Dura > 0 then
		task.delay(data.Dura, StatusEffects.RemoveState, character, stateName)
	end
end

But right now I can’t seem to figure it out.

1 Like

Could anyone help me out? I’m really confused on how should I go about this.

I’m trying to figure ts out and it’s not going, I really need some professional help

What exactly is the “transmit”? is it a remote event or bindable event?

BridgeNet that fires to the player to initialize on the client.

I have not worked with bridge net before but I reccomended reading up on its devforum page to get some more info

I didn’t complain about that being the issue, it’s about structuring the tables, it’s all written in the post.

Bump asodhuasouidhasuioda Bump asodhuasouidhasuioda

So what you call
StatusEffects.AddState(…)
and then it adds the state and updates the character?
And when a character wants to add a state, it what checks it’s own state first?