Using sletinick's Signal Module, I want to do it across two different modules

I am making a State System.

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

Create a separate module for state handling:

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

Now that should work.

2 Likes

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.

1 Like

bump unfortunately since I struggle to further anything on the breakthrough of fixing this bug

1 Like

Did it?

charcharcharchar

1 Like

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.

1 Like

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:

  1. 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

  1. 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.

2 Likes

Yay! I’m glad I could help you. Feel free to reach out if you have any questions or concerns.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.