Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Module script help?

Hi I am making an obby where when you touch a brick you get teleported somewhere however this is not working for me. I have recently had to change all of the scripts and decided to switch to one module script and then tons of scripts that require it so that I would only have to change the script once. This does not seem to be working. Here are the scripts > Module Script

local _M = {}

function _M.lose()
	
end

function _M.win()
	Ting = 0
	print("test")
	script.Parent.Touched:connect(function(p)
		print("test2")
	if p.Parent:findFirstChild("Torso") and Ting == 0 then
		Ting = 1
		local plyr=game.Players:GetPlayerFromCharacter(p.Parent)
		local level=plyr.level
		level.Value=level.Value+1
		local location=game.Workspace.Levelstarts:FindFirstChild("Level"..(level.Value))
		p.Parent.Torso.CFrame = location.CFrame + Vector3.new(0,5,0)
		Ting = 0
	end 
end)

end

return _M

test2 not being printed > Script inside of brick

local teleporter= require(game.Workspace.Teleporter)
teleporter.win()

I would like the script.Parent.Touched part be in the module script but if this is not possible then please tell me.

1 answer

✓ Accepted answer

You can't/shouldn't really do this.

Instead, pass the brick you're interested in as a parameter:

-- module
function _M.win(brick)
	Ting = 0
	print("test")
	brick.Touched:connect(function(p)
		......
-- script
local teleporter = require(workspace.Teleporter)
teleporter.win( script.Parent )

This discussion is preserved as it was. New answers, comments, and votes are closed.