Connecting a module function in the server script

I don’t know much about modules yet, so I don’t know if I’m doing it right. I have a module with the reset function, I want to trigger this function in the server script, when the player dies or reset, it clears the values. It is not cleaning when the player dies, which may be wrong, in both scripts.

local module = {}

local function reset()
	local parentModel = script.Parent
	
	parentModel.BluePlayer.Material = "Plastic"
	parentModel.RedPlayer.Material = "Plastic"
	parentModel.turn.Value = "NONE"
	parentModel.blueEmpty.Value = true
	parentModel.redEmpty.Value = true
	parentModel.redPlayer.Value = "EMPTY"
	parentModel.bluePlayer.Value = "EMPTY"
	parentModel.nTurn.Value = 1
	clearBoard()
end

function module.died()  -- have to specify something within the () ?
	reset()
end

return module

local moduleScript = require(script.Parent.ModuleScript)
local parentModel = script.Parent

local name1 = script.Parent.redPlayer.value
local player1 = game.Players:FindFirstChild(name1)

local name2 = script.Parent.bluePlayer.Value
local player2 = game.Players:FindFirstChild(name2)

function died1(player1) -- is this right? 
	print("died")
	moduleScript.died()
end

function died2(player2) -- is this right?  
	print("died")
	moduleScript.died()
end

player1.Died:connect(died1)
player2.Died:connect(died2)

Where is the module script placed? You also made a mistake for your module script.

It should be function module.reset() instead of local function reset().

 function module.reset()
	local parentModel = script.Parent
	
	parentModel.BluePlayer.Material = "Plastic"
	parentModel.RedPlayer.Material = "Plastic"
	parentModel.turn.Value = "NONE"
	parentModel.blueEmpty.Value = true
	parentModel.redEmpty.Value = true
	parentModel.redPlayer.Value = "EMPTY"
	parentModel.bluePlayer.Value = "EMPTY"
	parentModel.nTurn.Value = 1
	clearBoard()
end

Let me know if this helped :wink:

1 Like

1 Like

Yea the placement is fine, just edit the module script

i changed to function module.reset. but still not cleaning

modules are usually placed in server script service or startplayer scripts, try putting your module in one of those places

Make sure there isn’t any local next to the function or else it won’t work.

I redid my scripts. but it still doesn’t work. Am I specifying right?