Priority3
This module is made to eliminate issues like: running while crouching or dashing while being stunned by using priority based states.
you can use this module to easily add states with priorities to objects and have full control over them
Listen!
Changing states in client scripts will not update them on the server
Download
Roblox marketplace
Github
Adding States
Method1
This method is just a quick way of adding States to every Statemachine created by the Module
-
Add your priorities inside of the module named HumanoidProperties
Method2
Use this method if you want to add specific states to some of the classes
-----------// Server Script//-----------
-- Module
local Priority3 = require(...) -- require the module
-- State Configs
local stateConfig1 = Priority3.CreateStateConfig({
Name = "Walking",
Priority = 1,
Priorities = {
WalkSpeed = 16,
JumpPower = 50,
}
})
-- Variables
local character = ... -- get character
local humanoid = character:WaitForChild("Humanoid") -- Get humanoid
local class = Priority3.GetClass(humanoid) -- Get/Create Statemachine for Humanoid
-- Adding States
class:AddState(stateConfig1)
Method3
The difference between this method and the second method is that you have more control over the properties changing
-----------// Server Script//-----------
-- Module
local Priority3 = require(...) -- require the module
-- State Configs
local stateConfig1 = Priority3.CreateStateConfig({
Name = "Walking",
Priority = 1,
})
-- Variables
local character = ... -- get character
local humanoid = character:WaitForChild("Humanoid") -- Get humanoid
local class = Priority3.GetClass(humanoid) -- Get/Create Statemachine for Humanoid
-- Adding States
class:AddState(stateConfig1)
class:ListenToChange(stateConfig1.Name):Connect(function(enabled, active)
if active then
-- You can use TweenService for this if you want!
humanoid.WalkSpeed = 16
humanoid.JumpPower = 50
end
end)
Example Script
-----------// Toggle Sprint (server) //-----------
local remote = ...
remote.OnServerEvent:Connect(function(player, enable)
local humanoid = player.Character:WaitForChild("Humanoid")
local class = Priority3.GetClass(humanoid)
class:SetEnabled("Running", enable)
end)
-----------// Toggle Sprint (client) //-----------
local remote = ...
local character = ...
local humanoid = character:WaitForChild("Humanoid")
local class = Priority3.GetClass(humanoid)
local function ToggleSprint()
local enable = not class.States.Running.Enabled
-- To make sprinting intuitive for Players with bad internet
-- we will first toggle sprint on the Client and
-- then we will use RemoteEvent to do it on the Server
class:SetEnabled("Running", enable)
remote:FireServer(enable)
end
-- Use the ToggleSprint() function however you want.
- Bonus!
-----------// Stamina Check for Sprinting (server) //-----------
class:AddCheck("Running", "StaminaCheck", function()
if humanoid:GetAttribute("Stamina") > 0 then
return true -- allow the module to activate the state
end
end)
-----------// Sprinting Animation (client) //-----------
-- Module
local Priority3 = require(...) -- require the module
-- Variables
local character = ... -- get character
local humanoid = character:WaitForChild("Humanoid") -- get humanoid
local class = Priority3.GetClass(humanoid) -- get/create statemachine for humanoid
-- Functions (updating animation)
local function UpdateSprintAnimation(enabled, active)
if active then
-- play sprint animation here
else
-- stop sprint animation here
end
end
class:ListenToChange("Running"):Connect(UpdateSprintAnimation)
API Document
Moved to Github
Its my first time using Github so lmk if I’m using it wrong
Other Versions
Priority4:
PriProp: