Hello, I want to make function in the module to use it everywhere, but I can’t do it.
Whatever I do I always get the error: attempt to index nil with ‘leaderstats’. What am I doing wrong? Can someone help me?
Sorry if this question seems weird to you (I already tried to find the answer to my question, but I couldn’t.)
I tried to create variables but it doesn’t help.
ModuleScript -
local module = {}
function module.AddMoney(Player)
Player.leaderstats.Money.Value = Player.leaderstats.Money.Value + 1
end
return module
ServerScript -
local Module = require(game.ServerStorage.ModuleScript)
script.Parent.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
Module.AddMoney()
end
end)
This errors again because you need to check if the part that touched is part of a player’s character.
script.Parent.Touched:Connect(function(Hit)
if game.Players:GetPlayerFromCharacter(Hit.Parent) then
Module.AddMoney(game.Players:GetPlayerFromCharacter(Hit.Parent))
end
end)