Module script functions not working

Hey! I recently discovered an issue with scripts and module scripts. So basically I want to make a leaderstats script. I have this :
image

The content of the leaderstats script is :

local Players = game:GetService("Players")

print("The leaderstats script run perfectly!")

local CreateLeaderstats = require(script.CreateLeaderstats)
local Configuration = require(script.Configuration)
local SaveData = require(script.SaveData)

local Pad = workspace.WinPad.Pad

Players.PlayerAdded:Connect(CreateLeaderstats.OnJoin)
Players.PlayerAdded:Connect(SaveData.LoadData)

Players.PlayerRemoving:Connect(SaveData.Save)

game:BindToClose(function()
	for i, v in pairs(Players:GetPlayers()) do
		SaveData.Save(v)
	end
end)

Pad.Touched:Connect(Configuration.OnTouch)

The content of the module script is :

local CreateLeaderstats = {}

print("The module script run perfectly too!")

function CreateLeaderstats.OnJoin(player)
	print("Is that working ?")
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = CreateLeaderstats.SetNameTo("leaderstats")
	
	local Win = Instance.new("NumberValue", leaderstats)
	Win.Name = CreateLeaderstats.SetNameTo("Win")
	Win.Value = CreateLeaderstats.SetValueTo(0)
end

function CreateLeaderstats.SetNameTo(text)
	return text
end

function CreateLeaderstats.SetValueTo(value)
	return value
end

return CreateLeaderstats

I used moduleScripts and some stuffs to organize my scripts because I’m never organize, anyways.

So the problem, is that the leaderstats script run perfectly print("The leaderstats script run perfectly!") it print in the output. The ModuleScript works perfectly too print("The module script run perfectly too!") it print in the output.

But, when a player join the OnJoin function in CreateLeaderstats moduleScript doesn’t run and I can’t find the issue.

If someone can help it, thanks !

Sorry if this isn’t clear, and you didn’t understand. I’ll try to explains you, if you don’t.

1 Like

You’re not calling the OnJoin function with parenthesis and passing a player object parameter

And the same can be said with all of your functions in that same script

1 Like

Oh weird because this script is from 3 days and it worked perfectly until now. Can you show me the correct script please ? My brain burning because of thinking

I don’t think it’s anything to do with the module. Try replacing CreateLeaderstats.OnJoin with just print

Players.PlayerAdded:Connect(function(Player)
CreateLeaderstats.OnJoin(Player)
SaveData.LoadData(Player)
end

That shouldn’t be necessary theoretically, though. OP’s solution works just fine on my computer. I don’t think it has anything to do with how they’re passing the function into the :Connect listener.

It is as there is a double same connection which is useless, and he have to send the Player as argument to the module functions.

I didn’t understand can you say that again with the script please ?

I tried it didn’t worked, however the module script work perfectly only the functions are somehow broken

Try this:

Players.PlayerAdded:Connect(function() print("TEST") end)

Does it fire?

Any chance it is this line that broke your script ?
Maybe it is not found so the script get stuck, because it is weird that your function isn’t working correctly, there doesn’t seem to be something wrong.

local Pad = workspace.WinPad.Pad

didn’t worked
image

Ignore the “i” thing it’s from another script

Your script is in server script service right ?

The Model is there
image

And the Part doesn’t return an error-type

Yeah
image

Yeah but the script can run before the model was loaded into the workspace.
You could maybe try to make it as a comment and add a print under it to check if it eventually can be because of it

Test1

local Pad = workspace.WinPad.Pad
print("test")

Test2

-- local Pad = workspace.WinPad.Pad
print("test")

Weird the first print thing worked but after the modules it didn’t

local Players = game:GetService("Players")

print("The leaderstats script run perfectly!")

local CreateLeaderstats = require(script.CreateLeaderstats)
local Configuration = require(script.Configuration)
local SaveData = require(script.SaveData)

--local Pad = workspace.WinPad.Pad
print("test")

Players.PlayerAdded:Connect(function() print("TEST") end)

Players.PlayerRemoving:Connect(SaveData.Save)

game:BindToClose(function()
	for i, v in pairs(Players:GetPlayers()) do
		SaveData.Save(v)
	end
end)

--Pad.Touched:Connect(Configuration.OnTouch)

image

Try:

game.Players.PlayerAdded:Connect(function(player)
CreateLeaderstats.OnJoin(player)
end)

Sorry, I’m on mobile rn.

Alright, so it seem like you just need to add waitforchild to your modules requirements.

local Players = game:GetService("Players")

print("The leaderstats script run perfectly!")

local CreateLeaderstats = require(script:WaitForChild("CreateLeaderstats"))
local Configuration = require(script:WaitForChild("Configuration"))
local SaveData = require(script:WaitForChild("SaveData"))

--local Pad = workspace.WinPad.Pad
print("test")

If it doesn’t work, then it probably come from your Configuration or SaveData module, try do this… maybe something in these modules yield / stuck your main script

local CreateLeaderstats = require(script:WaitForChild("CreateLeaderstats"))
print("test1")
local Configuration = require(script:WaitForChild("Configuration"))
print("test2")
local SaveData = require(script:WaitForChild("SaveData"))
print("test3")

It’s okay. It still didn’t worked… I really don’t understand why.