Module function not working despite being executed?

Concept: I want to make modules that contain functions for abilities for each one of my characters that activate whenever I press their buttons. However in the following code the output says my module function was executed when it really wasnt. I can provide more details if asked!

This is the script where the module function is ran, I included some comments to describe what’s going on and the result of some debug prints


--Abilities In Game

--this isnt the full script but i can provide more details if asked

local function syncabilities(infomodule, abilitymodule)
	for _, connection in pairs(abilityconnections) do
		connection:Disconnect()
	end
	
	local ability1info = infomodule.Abilities["Ability1"]
	local ability2info = infomodule.Abilities["Ability2"]
	
	Ability1TextLabel.Text = ability1info.Name
	Ability2TextLabel.Text = ability2info.Name
	
	local cooldown1 = ability1info.Cooldown
	local cooldown2 = ability2info.Cooldown
	
	Ability1Button.Image = ability1info.Image
	Ability2Button.Image = ability2info.Image
	
	abilityconnections.ability1 = Ability1Button.Activated:Connect(function()
		
		--this is where the problem is yo
		
		print("Ability1 Started")
		local success, error = pcall(function()
			abilitymodule.Ability1(player.Character)
			print("Ability1 Ended")
		end)
		
		if not success then
			print("Error in ability1: " .. error)
		end
		
		--it prints ability 1 started and ability 1 ended without error but the function doesnt run
			
		
			

			
		Ability1CooldownLabel.Visible = true
		
		Ability1Button.Active = false
		for count = cooldown1, 0, -1 do
			Ability1CooldownLabel.Text = count
			task.wait(1)
		end
		Ability1CooldownLabel.Visible = false
		Ability1Button.Active = true
	end)
	
	abilityconnections.ability2 = Ability2Button.Activated:Connect(function()
		
		--ignore this my main focus is ability 1 lol
		Ability2CooldownLabel.Visible = true
		Ability2Button.Active = false
		abilitymodule.Ability2(player.Character)
		for count = cooldown2, 0, -1 do
			Ability2CooldownLabel.Text = count
			task.wait(1)
		end
		Ability2CooldownLabel.Visible = false
		Ability2Button.Active = true
	end)
end

--when the game starts, they are given a different in game character

GameStartEvent.OnClientEvent:Connect(function()
	local equipped = CharacterEquipped.Value
	local character = CharactersFolder:FindFirstChild(equipped)
	local charactermodel = player.Character
	if not character then return end
	local infomodule = require(character:FindFirstChild("InfoPanel"))
	local abilitymodule = require(AbilityModules:FindFirstChild(equipped))
	if not infomodule or not abilitymodule then return end
	syncabilities(infomodule, abilitymodule)
	
	--just some debug
	print(abilitymodule.Ability1)
	--this ended up printing a functionx0 something
	print(abilitymodule)
	--this just printed a table of the module with ability1, ability2, and it said it ran on the client which is true
	print(AbilityModules:FindFirstChild(equipped).Name)
	--this just printed the module name
	
	AbilitiesUI.Enabled = true
	
	
	
end)

here’s the module itself, again some comments so you know whats going on here


local Zorble = {}
--zorble's the character name hes like an alien i guess

function Zorble.Ability1(character)
	wait(2)
	--even though there's a wait here the "Ability1 Ended" print shows up instantly so this first line doesnt even run
	print("Abilityfunctionentered")
	--this didnt print either, the rest of the function didnt do anything either
	
	-- these are all just different parts of the ingame character i passed in
	local hrp = character:FindFirstChild("HumanoidRootPart")
	local AnimSaves = character:FindFirstChild("AnimSaves")
	local humanoid = character:FindFirstChild("Humanoid")
	local Animator = humanoid:FindFirstChild("Animator")
	local Raygun = character:FindFirstChild("Raygun")
	
	print("all is good")
	local RaygunFireTrack = Animator:LoadAnimation(AnimSaves.RaygunFire)
	
	RaygunFireTrack:Play()
	
	RaygunFireTrack:GetMarkerReachedSignal("GunAppear"):Wait()
	
	Raygun.Transparency = 0
	
	RaygunFireTrack:GetMarkerReachedSignal("Fire"):Wait()
	
	print("kapow!")
	
	RaygunFireTrack.Ended:Wait()
		
	Raygun.Transparency = 1
	
end


--ignore ability2
function Zorble.Ability2(character)
	print("nothing here yet")
end

return Zorble


extra details:
this is running on the client,
the module is located in a folder in ReplicatedStorage,
the rest of the other script goes normally without executing the module function,
i removed sanity checks in the module function and it still doesnt work
thanks for reading!!

1 Like

You’re sure this is the whole module? e.g. there’s no duplicate function declared within the module?

	local abilitymodule = require(AbilityModules:FindFirstChild(equipped))

And there’s no chance it’s accidentally executing a different modulescript, e.g. a duplicate by accident, perhaps with different contents? Make sure there is only 1 child with the name of whatever is equipped, otherwise :FindFirstChild could be returning the wrong one.

I suspect if you add a print to the beginning of the Ability1 function, it won’t print, even before the wait().

  1. yep, this the copy and paste of the whole module


only 1 child

  1. originally i had a print statement at the beginning that still wouldn’t print so your suspicions are correct

During runtime, in command line require your “Zorble” module and try Zorble.Ability1(). See if that gives the same result

alrighty here’s the command i used to attempt to run the function:

require(game.ReplicatedStorage.AbilityModules.Zorble).Ability1(workspace.Default)
-default is the name for my charactermodel

in the output nothing happened other than the command itself popping up

Screenshot 2025-11-24 221142

this is one of my first times using the command bar so see if I got something wrong there

Well your Zorble.Ability1 is being overwritten somewhere. Try CTRL+Shift+F and search for “.Ability1” or something along the same line and make sures its not being overwritten

Instead, place a breakpoint on the function call and step into said function. See where that takes you, @binodrobin

3 Likes

so i ended up commenting all instances where “Ability1” showed up (without breaking the code of course) and it ended up giving me the exact same results as before

here’s the list

to address that replicatedstorage.Characters module, that’s for the shop and I made sure to comment the function that requires the shop to turn it all off
in the coreui i commented all that contained “Ability1” except for variables

also when i mean same result I mean
“Ability1 Started” and “Ability1 Ended” fire instantaneously upon activating the function, but the function doesnt run

i’ll take a break and try @Ziffix 's solution in a bit i just need to learn breakpoints aswell since im a new scripter

alright so using the breakpoints I was able to step into the function and see what happened,
and I think a studio error happened in my last couple of sessions because all of the sudden I was able to have my function communicating between the module and the client.
i am genuinely so happy that this is fixed thank you VERY VERY MUCH for telling me about breakpoints

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