What is the best way to handle settings and configs?

hey, so i’m working on a system that handles custom humanoid states such as;

sprinting
prone
crouch
sit
idle
and walk

(the point is i want to add more later for tools and interactables)

now, i have a basic handler module set up but for the states themselves i want it to be easily duplicated and customizable.

what would be better? using a function inside that’s just called whenever a designated key is pressed? or my current idea/method; (any addition inputs or methods are appreciated)

SPRINT AS AN EXAMPLE

local state = {}

-- sprint example

state.Idle = false -- controls whether this is the idle state or not

state.WalkSpeed = 18
state.Animation = "Sprint" -- nil for no animation
state.TransitionAnimation = nil -- determines if there's a transition animation, nil for no animation
state.TransitionTime = 0 -- how long ur transition is, 0 for no animation.
state.Key = Enum.KeyCode.LeftShift
state.Push = true -- if you let go of the key it will end the state

return state

handler so far:

local mod = {}

local services = require(script.Parent:WaitForChild("Services"))
local en = require(script.Parent:WaitForChild("Enums"))

function mod.StateUpdate(character:Model, player:Player, humanoid:Humanoid)
	
	
	
end

function mod.DisconnectCharacter(character:Model, player:Player, humanoid:Humanoid, connectiontable)
	
	for i,v in pairs(connectiontable) do
		v:Disconnect()
	end
	
	
end

function mod.InitCharacter(character:Model)
	
	local player = services.PLR:GetPlayerFromCharacter(character)
	local humanoid = character:FindFirstChildWhichIsA("Humanoid")
	
	local connectedfunctions = {}
	
	local updateconnection = services.RUS.Heartbeat:Connect(function()
		mod.StateUpdate(character, player, humanoid)
	end)
	
	table.insert(connectedfunctions, updateconnection)
	
	local function disconnect()
		mod.DisconnectCharacter(character, player, humanoid, connectedfunctions)
	end
	
	humanoid.Died:Connect(disconnect)
end

function mod.SetState(State:string)
	
end

return mod

image

essentially; what is the best method of creating a configuration that is easily duplicate able but able to hold specific customizations that may only be unique to a certain state.

1 Like