I currently have a brick which when touched increases the player score trough a function stored in a ModuleScript

local Storage = game:GetService("ServerStorage")
local Score = require(Storage.ScoreManager)

script.Parent.Touched:Connect(Score.ChangeScore)`

And here is the ModuleScript:

local ScoreManager = {}

function ScoreManager:ChangeScore(otherPart)
	local Player = otherPart.Parent
	_G.ScoreTable[Player] = _G.ScoreTable[Player] + 1
	_G.ScLeadStats.Value = _G.ScoreTable[Player]
end

return ScoreManager

The Touched event only has the parameter otherPart, of which I try to get the parent name to get the affected player name (I don't need to use DataStores or UserId for this because it's only meant to be temporary data) but otherPart is always nil. What am I doing wrong?

5 comments

0

Connect an anonymous function that calls ChangeScore. script.Parent.Touched:Connect(function() Score:ChangeScore(otherPart) end)

0

I still get the same error.

0

Did you pass in otherPart?

0

Yes

0

All functions are anonymous in Lua nerd