The reason I am using this State System is because I rather just have a ChangedEvent equivalent deal with behavior than manually actually doing the States (e.g, Stun, Dodging, etc.)
I was going to handle it all in one module, but the issue occurs when one of the modules that handle the behavior of one of the states requires one of the Functions inside of the main State System Module, so to utilize it, I need to have the Signal connecting in a different module so I could avoid this recursive requiring.
function WrapperPlayer:CheckStateActivities(Player, State)
local profile = ProfilesHolders[Player.Name]
if profile[State].Activity then
for _, Blacklists in(profile[State].BlacklistedStates) do
if profile[Blacklists].Activity then
return true
else
return false
end
end
end
end
The needed function above ^
The issue in play
function DodgeStatus:Dodge(Player)
WrapperPlayer:ToggleState(Player, "P-Dodging")
WrapperPlayer:ToggleState(Player, "Dodging")
task.delay(0.2, function()
WrapperPlayer:ToggleState(Player, "P-Dodging")
end)
task.delay(0.5, function()
WrapperPlayer:ToggleState(Player, "Dodging")
end)
end
local StateHandler = {}
function StateHandler:ToggleState(Player, State)
local profile = ProfilesHolders[Player.Name]
-- toggle logic here
end
return StateHandler
Include functions to check state activities:
function StateHandler:CheckStateActivities(Player, State)
local profile = ProfilesHolders[Player.Name]
if profile[State].Activity then
for _, Blacklists in pairs(profile[State].BlacklistedStates) do
if profile[Blacklists].Activity then
return true
end
end
end
return false
end
return StateHandler
Import the StateHandler module and use its functions:
local StateHandler = require(script.Parent.StateHandler) -- Adjust path
function DodgeStatus:Dodge(Player)
StateHandler:ToggleState(Player, "P-Dodging")
StateHandler:ToggleState(Player, "Dodging")
task.delay(0.2, function()
StateHandler:ToggleState(Player, "P-Dodging")
end)
task.delay(0.5, function()
StateHandler:ToggleState(Player, "Dodging")
end)
end
I believe that’s what I was doing earlier, but the issue was still overall trying to get the signal -
StateSig:Connect(function(Player, State, Activity)
local Character = Player.Character
local Humanoid = Character.Humanoid
if Activity then
if State == "Stunned" then
StunStatus.Stun(Humanoid, 0)
elseif State == "Dodging" then
elseif State == "Blocking" then
end
end
end)
in a whole different module so what you are recommending could work out.
I can’t try it, due to the secondary issue with your method, which is firing the actual signal so I can have the behavior run and not manually execute it.
I was saying, this was the method I would’ve been the best choice, but it becomes difficult when that roadblock occurs, and the fact that it’s exclusively server makes it a bit more of an issue.
Summary:
In a compressed way, the issue is that I cannot Fire from one signal and hope for it to occur on a different module, but this would be the desired method I’d like to do. I just don’t know a proper way of sending the Signal to the other module script. If I figured that out, then your method could work.
To achieve this, you can use Roblox’s built-in BindableEvent and BindableFunction objects. Here’s how you can modify your code to do that:
Modify the StateHandler module to use BindableEvent:
local StateHandler = {}
StateHandler.StateToggled = Instance.new("BindableEvent")
function StateHandler:ToggleState(Player, State)
local profile = ProfilesHolders[Player.Name]
-- Toggle logic here
-- After you toggle the state, you can fire the event to signal the change.
StateHandler.StateToggled:Fire(Player, State)
end
function StateHandler:CheckStateActivities(Player, State)
local profile = ProfilesHolders[Player.Name]
if profile[State].Activity then
for _, Blacklists in pairs(profile[State].BlacklistedStates) do
if profile[Blacklists].Activity then
return true
end
end
end
return false
end
return StateHandler
Modify the DodgeStatus module to listen for the event:
local StateHandler = require(script.Parent.StateHandler)
function DodgeStatus:Dodge(Player)
StateHandler:ToggleState(Player, "P-Dodging")
StateHandler:ToggleState(Player, "Dodging")
task.delay(0.2, function()
StateHandler:ToggleState(Player, "P-Dodging")
end)
task.delay(0.5, function()
StateHandler:ToggleState(Player, "Dodging")
end)
end
StateHandler.StateToggled.Event:Connect(function(Player, State)
-- Handle the state change here, e.g., update the UI or perform other actions.
print("State changed:", Player.Name, State)
end)
With this setup, the StateHandler module fires the StateToggled event when a state is toggled. The DodgeStatus module listens for this event and handles the state changes. You can replace the print statement with your desired logic to respond to state changes.