Skip to main content

πŸ€–πŸ”„ State Machine

Now that we have 1 state we can already make our state machine! Don't worry, we will be covering transitions and making our red state next! Now in a server or local script create a state machine with the following code...

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local RobloxStateMachine = require(ReplicatedStorage.RobloxStateMachine)

local states = ReplicatedStorage.States -- Reference to our states folder

local stateMachine = RobloxStateMachine.new("Blue", -- This is the initial state of our machine
{
require(states.Blue) -- This is an array of our states
},
{
part = workspace.myPart -- This is the data that our transitions and states will have access to
}
)

Running the game will now turn out part blue as it will be entering the blue state! If you see we are giving the StateMachine the information about what "part" is. It allows us to access the workspace part from our states and transitions!