Need help with proximity prompt

I have a script that makes a table dissapear and a new one appear but the old table leg is the only part that dissapears and the new table appears but it looks weird because there are 2 tables on top of each other.

local pp = script.Parent.ProximityPrompt2
pp.Triggered:Connect(function(player)
	if player.leaderstats.Cash.Value >= 25 then
		player.leaderstats.Cash.Value -= 25
		for i, child in ipairs((script.Parent.Parent.TableL1:GetChildren())) do
			if child.ClassName == 'Part' then
				child.Transparency = 1
				child.CanCollide = false
				wait(3)
				for i, child in ipairs((script.Parent.Parent.TableL2:GetChildren())) do
					if child.ClassName == 'Part' then
						child.Transparency = 0
						child.CanCollide = true
						wait(1)
						pp:Destroy()
					end
				end
			end
			end
	end
end)
1 Like

Just destroy the table and clone a new one from, say replicated storage.

You’re adding another loop inside of the first one. Loop through table one, and then table two.

local pp = script.Parent.ProximityPrompt2

pp.Triggered:Connect(function(player)
	if player.leaderstats.Cash.Value >= 25 then
		player.leaderstats.Cash.Value -= 25
		for i, child in ipairs((script.Parent.Parent.TableL1:GetChildren())) do
			if child.ClassName == 'Part' then
				child.Transparency = 1
				child.CanCollide = false
            end
        end
		for i, child in ipairs((script.Parent.Parent.TableL2:GetChildren())) do
			if child.ClassName == 'Part' then
				child.Transparency = 0
				child.CanCollide = true
            end
        end
	pp:Destroy()
    end
end)

1 Like

How would I do that? Could you show me?

Edited.
(thanks roblox for making me type this)

For the first table it loads slowly is there a reason or is my game just lagging?

local CanBeUsed = true
script.Parent.ProximityPrompt.Triggered:Connect(function(player)
	if CanBeUsed == true then
		if player.leaderstats.Cash.Value >= 10 then
			CanBeUsed = false
		player.leaderstats.Cash.Value -= 10
			local Table = script.Parent.Parent.TableL1
		for i, child in ipairs((Table:GetChildren())) do
			if child.ClassName == 'Part' then
				child.Transparency = 0
					child.CanCollide = true
					wait(.5)
					script.Parent.ProximityPrompt.Enabled = false
					script.Parent.ProximityPrompt2.Enabled = true
					
				end
			end
		end
	end
end)

Because you have a wait(0.5) in there, which is not needed.
You should also put script.Parent.ProximityPrompt.Enabled = false and script.Parent.ProximityPrompt2.Enabled = true after the loop.