HELP! connector changed not working

hello.
i am trying to make this work:


function Create_Room()
if script.SECOND_Room.Value ~= nil then
script.SECOND_Room.Value:Destroy()
else
end
	local Rooms = script.Rooms_Folder.Value:GetChildren()
	local Room = Rooms[math.random(1, #Rooms)]
	if Room ~= nil then
		local New_Room = Room:Clone()
		New_Room.Parent = game.Workspace
		script.Next_Room.Value = New_Room
		script.Trigger.Value = script.Next_Room.Value:FindFirstChild("END")
		task.wait()
		script.Next_Room.Value:SetPrimaryPartCFrame(script.Current_Room.Value:WaitForChild("END").CFrame)
		task.wait()
		script.Current_Room.Value = script.SECOND_Room.Value
		script.Current_Room.Value = New_Room
		script.Next_Room.Value = nil
script.Trigger.Value.Touched:Connect(function()
			Create_Room()
end)
end
end

script.Trigger.Value.Touched:Connect(Create_Room)

my problem is that after the value at the connection changed, it will still connect to the old value and didnt even notice that the objectvalue has changed!

any way to fix this?

also sorry for the bad formating

A simple fix would be to check if the Value of the ObjectValue has changed by using Instance.Changed

You should also use a Variable to Store the Connection rather than just have it out.

local connection = Instance.Touched:Connect(function) -- Variable Stores Connection

Since we have the Connection under a Variable, we can check if the Connected or is Disconnected, we can then use Event:Disconnect() to stop the Event, so we can replace it with the new Connection

local connection -- our Variable

connection = Instance.Touched:Connect(function)

connection:Disconnect() -- stops Connection

So with this, we are able to do this:

	script.Next_Room.Value = nil
connection = script.Trigger.Value.Touched:Connect(function() -- Stores Connection
    Create_Room()
end)
end 
end

script.Trigger.Changed:Connect(function(newValue) -- When the value changes
    connection:Disconnect() -- Disconnects 
    connection = script.Trigger.Value.Touched:Connect(function() -- new Connection
        Create_Room()
    end)
end)

my problem is taht the old trigger part value still triggers the script. does this script fix it?

It should, With the code, you are basically Disconnecting the old Connection and Replacing it with the new Value

also what are those 3 ends for?

1 Like

those ends are weird and im really sure it would break the code

Thats the other code from your script, to give you an idea on where to put the code

so this will be the end code???

script.Rooms_Folder.Value.Parent = game.ServerStorage





TRIGGER = script.Parent.START:FindFirstChild("END")


local db = true
function Create_Room()
if db then db = false
end

script.ROOM_AMOUNT.Value = script.ROOM_AMOUNT.Value + 1

task.wait()

	local Rooms = script.Rooms_Folder.Value:GetChildren()
	local Room = Rooms[math.random(1, #Rooms)]
	if Room ~= nil then
		local New_Room = Room:Clone()
		New_Room.Parent = script.ACTIVE_ROOMS_FOLDER.Value
		New_Room.Name = script.ROOM_AMOUNT.Value
		TRIGGER:Destroy()
		TRIGGER = New_Room:FindFirstChild("END")
		task.wait()
		New_Room:SetPrimaryPartCFrame(script.Current_Room.Value:WaitForChild("END").CFrame)
		task.wait()
		script.Current_Room.Value = New_Room
		task.wait(1)
		db = true

end
	TRIGGER.Touched:Connect(function()
		Create_Room()
	end)
end

script.Next_Room.Value = nil
connection = script.Trigger.Value.Touched:Connect(function() -- Stores Connection
	Create_Room()
end)


script.Trigger.Changed:Connect(function(newValue) -- When the value changes
	connection:Disconnect() -- Disconnects 
	connection = script.Trigger.Value.Touched:Connect(function() -- new Connection
		Create_Room()
	end)
end)

Looks like it.

1 Like

k i am gonna give you the solution :+1: please check your messages so we can go on solvong my problem ok?

1 Like