Values not updating/being read improperly

Hey, so I’m trying to fix up some old code I wrote awhile back, it’s a event host system where people can host events and walls and stuff appear around the pad as well as some text. It works great the first time you do it, however, if you host an event, and then end the event, and move to another pad and host an event there, the old stuff (walls and text and stuff) appear again as well as the new stuff appearing. Why is the old stuff appearing?

Here’s my server script:

game.Players.PlayerAdded:Connect(function(player)
	local newValue = Instance.new("BoolValue")
	newValue.Name = "eventActive"
	newValue.Parent = player
end)

local padActivated = game.ReplicatedStorage.EventStarted

padActivated.OnServerEvent:Connect(function(plr, ActivatedPad)
	local selectedpad = nil
	local walls = nil
	print('pad activated has been fired!')
	plr:WaitForChild("eventActive").Value = true
	local pads = game.Workspace.Pads
	selectedpad = pads:FindFirstChild(ActivatedPad)
	print(selectedpad.Name)
	
	walls = selectedpad:WaitForChild('walls'):GetChildren()
	print(walls)
	local plrgui = plr:WaitForChild('PlayerGui')
	local hostguif = plrgui.hostGUI
	
	--Display
	local display = selectedpad.event.BillboardGui
	local et = display.EventText
	local rt = display.RankText
	local st = display.StatusText
	
	--GUI Texts
	local ev = hostguif.Frame.Event
	local rv = hostguif.Frame.RR
	local sv = hostguif.Frame.Status
	
	--Events
	local Events = hostguif.Frame.Events:GetDescendants()
	for _,event in pairs(Events) do
		if not event:IsA("UIListLayout") then
			event.MouseButton1Click:Connect(function()
				local eventname = event:GetAttribute('EventName')
				et.Text = eventname
				ev.Text = 'Event: '..eventname
				local eventcolor = event:GetAttribute('Color')
				et.TextColor3 = eventcolor
			end)
		end
	end
	
	--Rank Requirement
	local rrs = hostguif.Frame.Ranks:GetDescendants()
	for r,rr in pairs(rrs) do
		if not rr:IsA("UIListLayout") then
			rr.MouseButton1Click:Connect(function()
				rt.Text = rr.Name
				rv.Text = 'Rank(s): '..rr.Name
			end)
		end
	end
	
	--Status
	local statuses = hostguif.Frame.StatusGroup:GetDescendants()
	for s,status in pairs(statuses) do
		if status.Name ~= 'UICorner' then
			status.MouseButton1Click:Connect(function()
				st.Text = status.Name
				sv.Text = 'Status: '..status.Name
			end)
		end
	end
	
	local function createEvent()
		
		for _, wall in ipairs(walls) do
			wall.Transparency = 1
			wall.CanCollide = false
		end
		
		display.Enabled = false
		
		for i,wall in ipairs(walls) do
			print('wall found: ', wall.Name)
			wall.Transparency = 0.85
			if st.Text == 'Open' then
				wall.SpecialMesh.VertexColor = Vector3.new(0, 255, 0)
				wall.CanCollide = false
			elseif st.Text == 'Locked' then
				wall.SpecialMesh.VertexColor = Vector3.new(255, 0, 0)
				wall.CanCollide = true
			end
		end
		
		-- Pop up event
		display.Enabled = true
	end
	
	local statuschangeubtton = hostguif.ControlFrame.ImageLabel.ToggleLock
	statuschangeubtton.MouseButton1Click:Connect(function()
		if st.Text == 'Open' then
			st.Text = 'Locked'
			createEvent()
		elseif st.Text == 'Locked' then
			st.Text = 'Open'
			createEvent()
		end
	end)
	
	local endEventButton = hostguif.ControlFrame.ImageLabel.TextButton
	endEventButton.MouseButton1Click:Connect(function()
		for i,wall in pairs(walls) do
			wall.Transparency = 1
			wall.CanCollide = false
		end
		display.Enabled = false
		hostguif.ControlFrame.Visible = false
		plr:WaitForChild("eventActive").Value = false
		return
	end)
	
	--Fire Function
	hostguif.Frame.TextButton.MouseButton1Click:Connect(createEvent)
end)
1 Like

Whats inside of the:

walls = selectedpad:WaitForChild(‘walls’):GetChildren()

Is it preset walls or invisible walls that you change transparency, or just walls that you clone?