My door doesn't work

My door system doesn’t work, the output doesn’t show errors.

My module script used to open the door:

local TweenService = game:GetService("TweenService")

local door = {}

function door.Open(doorModel)
	doorModel:SetAttribute("Open", true)
	
	local cframe = doorModel.Hinge.CFrame * CFrame.Angles(0, math.rad(100), 0)
	local doorTween = TweenService:Create(doorModel.Hinge, TweenInfo.new(0.5), {CFrame = cframe})
	
	doorTween:Play()
end

function door.New(roomModel)
	local doorModel = workspace.Door:Clone()
	
	doorModel:PivotTo(roomModel.Exit.CFrame)
	doorModel:SetAttribute("Open", false)
	
	doorModel.Sensor.Touched:Connect(function(hit)
		local humanoid = hit.Parent:FindFirstChild("Humanoid")
		if humanoid and doorModel:GetAttribute("Open") == false then
			door.Open(doorModel)
		end
	end)
	
	doorModel.Parent = roomModel
	
	return doorModel
end

return door

Any help is appreciated, thanks.

2 Likes

Here is the script:

local room = require(script.Room)
local door = require(script.Room.Door)

local prevRoom = workspace.StartRoom
local firstDoor = door.New(prevRoom)

for i = 1, 1000 do
	prevRoom = room.Generate(prevRoom)
end

The other module used to generate rooms:

local door = require(script.Door)

local room = {}
room.info = require(script.RoomInfo)
room.lastTurnDirection = nil
room.random = Random.new()

function room.GetRandom(prevRoom)
	local totalRarity = 0
	for i, info in pairs(room.info) do
		totalRarity += info.Rarity
	end
	
	local randomRarity = room.random:NextNumber(0, totalRarity)
	local currentRarity = 0
	local randomRoom = nil
	for i, info in pairs(room.info) do
		currentRarity += info.Rarity
		if randomRarity <= currentRarity then
			randomRoom = workspace.Rooms[i]
			break
		end
	end
	
	local direction = room.info[randomRoom.Name]["Direction"]
	
	if (prevRoom.Name == randomRoom.Name)
		or (direction and direction == room.lastTurnDirection) 
	then
		return room.GetRandom(prevRoom)
	else
		if direction then
			room.lastTurnDirection = direction
		end
		return randomRoom
	end
end

function room.Generate(prevRoom)
	local randomRoom = room.GetRandom(prevRoom)
	local newRoom = randomRoom:Clone()
	
	newRoom.PrimaryPart = newRoom.Entrance
	newRoom:PivotTo(prevRoom.Exit.CFrame)
	
	local newDoor = door.New(newRoom)
	
	newRoom.Parent = workspace.GeneratedRooms
	
	return newRoom
end

return room

image

insert a script into the door module and set the script enabled to false from properties

image

then write this into the script:

local doorModel = script.Parent
local door = require(--//module that you want to add)

doorModel.Sensor.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid and doorModel:GetAttribute("Open") == false then
		door.Open(doorModel)
	end
end)

this part of the module must be like this:

I fixed the door myself. (by turning canTouch and canQuery)

anyways, thanks.

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