My script stops running at events

Currently I’m trying to only render abilities and stuff on specific clients. This is the code that I’m having trouble with (I’m putting it here so you can look back as I explain):

local repStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")

local brRemotes = repStorage:WaitForChild("BattleRelatedRemotes")
local modules = repStorage:WaitForChild("Modules")

local attackRemote = brRemotes:WaitForChild("AttackRemote")

local battleModule = require(modules:WaitForChild("ClientBattleModule"))

attackRemote.OnClientEvent:Connect(function(attacker, ability, hit, target, camLook)
	print("Signal received.")
	battleModule:RenderAbility(attacker, ability, hit, target, camLook)
end)

attackRemote.OnClientEvent:Connect(function() print("Hey!") end)

print(attackRemote.Name)

I have breakpoints on each un-indented line after “local modules”, but the last three don’t stop the script at all. The events do not connect and of course the print at the very end doesn’t run. My watch shows that all variables from before the events have been correctly assigned. Anybody have any idea what I’ve done wrong?

Edit: On further testing I’ve realised that the script stops running after:
local battleModule = require(modules:WaitForChild("ClientBattleModule"))

I’m now even more confused because I’ve triple checked that it’s pointing to the correct directory, and the module is already there when the script stops on this line’s breakpoint.

Hmm, check the ClientBattleModule and see if it requires the current script. I believe it might be circular requiring where one module requires the other infinitely but idk.

Either way, something is causing it to yield as you mentioned.

1 Like

Ahhh yes it was the ClientBattleModule, this whole time I’ve had game.Loaded:Wait() at the top. I didn’t realise that it would cause the module to yield forever. Thanks for your direction

1 Like

Oh, now that I look into the API I realize that is probably why in the script example there is an if statement before the game.Loaded:Wait() yield.

Script example in API:

if not game:IsLoaded() then
    game.Loaded:Wait()
end

So yeah I’m guessing the script ran when the game is already loaded so now it’s yielding forever probably. Really interesting thanks for highlighting this issue.

1 Like