How can I make this modulescript like local player (GnomeCode Door)

This is my modify code of GnomeCode’s script . I am trying to create this “door” that give player Score everytime they touch it and affect only that player(currently affect all player). I don’t really know how to use modulescript or modify it correctly. please any guide :sweat_smile:


local door = {}
local playerEnter = script.Parent.PlayerEnter

local debounce = false

local function updateScore(player)
	local leaderstats = player:FindFirstChild("leaderstats")
	if leaderstats then
		local score = leaderstats:FindFirstChild("Score")
		if score then
			score.Value = score.Value + 1  
		end
	end
end

function door.Open(doorPart, roomNumber, player)  
	doorPart.Color = Color3.new(0, 1, 0)
	playerEnter:Fire(roomNumber)

	updateScore(player)

	doorPart.CanCollide = false
	doorPart.Transparency = 0.5  
	wait(0.5)  
	doorPart:Destroy()  
end

function door.New(roomModel, roomNumber) 
	local doorPart = workspace.Door:Clone()

	doorPart.Position = roomModel.Exit.Position

	doorPart.Touched:Connect(function(hit)
		local humanoid = hit.Parent:FindFirstChild("Humanoid")

		if humanoid and not debounce then
			local player = game.Players:GetPlayerFromCharacter(hit.Parent) 
			if player then  
				debounce = true  
				door.Open(doorPart, roomNumber, player)  

				wait(1)  
				debounce = false  
			end
		end
	end)

	doorPart.Parent = roomModel

	return doorPart
end

return door

image

I am not entirely sure what you need help with as you never specify.
Could you give a description of what exactly you want to achieve/are having an issue with?

If you need a simple explanation of ModuleScripts, basically its a script utilized for functions that can be used in either multiple locations or to create “Objects”.

In this case, you are creating an “Object”, that object being a door. ModuleScripts can’t be used on their own, they must be required in a Server Script or LocalScript in order to run. The advantage to using ModuleScripts is that, if you have multiple instances of the same “Object”(like 10 doors that do the same thing, or similar), you can write 1 ModuleScript and if you ever need to change how they all work, you can just modify the 1 ModuleScript you have.

I recommend reading about ModuleScripts HERE as its better explained there.

1 Like

hello thank for reply, I’m sorry for bad explanation. Usually this module script affect everyone with MainServer, with it affect everyone the ‘door’ that give point when touch and destroy itself to prevent further more touched from that player, I’m thinking how can I possible to transfer gaining point from this door module(more local side?). I’m afraid to change anything in this modulescript or should I create another module for gaining point for each door I touch?

(I also read the Modulescript from creatorhub, but my brain isn’t really working)

you can ask me for more question

Either me or what, but I don’t really see anything wrong, try adding prints

Also modules is like normal scripts, but they are ran only aftrer you use require on them, also you can use them as table for info that you need on client and server (It needs to be there from start btw)

1 Like

Seems that you’re asking for the point adding to be on the client-side??
Easy; just make it a localscript which affects the localplayer only. But if you want it to replicate to the server-side too; id recommend Remote Events.

(LOCALSCRIPT ONLY!) if you want to delete the door upon touch; just do a

door.Touched:Connect(function(plr)
door:Destroy() -- has to be a localscript for the door to delete only on the players screen
1 Like

this. can you please elaborate more? I’m not really get it.

Update: I changed PlayerEnter from bindableEvent to remoteEvent, and moving some of function door.Open(doorPart, roomNumber, player) to starterplayerscript while updateScore(player) remain.
it actually work! I’m not really sure about safety but it finally work!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.