Hey! I recently discovered an issue with scripts and module scripts. So basically I want to make a leaderstats script. I have this :
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.
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
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.
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.
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
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)
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")