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!
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
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)