Card door script keeps getting errors

So, I am learning how to use tables and I tried making an script and for some reason it keeps getting errors, I tried all way to solve them but I couldn’t.

Here’s my script

local tables = {script.Parent.Door,script.Parent.Key.Union, script.Parent.Floor}
local newp = Instance.new("BoolValue")
newp.Value = false
local cd = false
local cd2 = false
for i = 1,#tables do
  
  	tables[2].Touched:Connect(function(player)
  		if cd == false then
  		newp.Name = "KeyCard"
  		local e = Instance.new("Part", script.Parent.Key)
  		e.Name = "Union"
  		e.Anchored = true
  		e.Position = Vector3.new(17.468, 1, 9.816)
          tables[2]:Destroy()
  		print(tables[1])
  		newp.Value = true
  		cd = true
  		newp.Parent = workspace	
  		end
  	
  	tables[1].Touched:Connect(function(player2)
  	if newp.Value == true and cd2 == false then
  		tables[1].Transparency = 1
  		tables[1].CanCollide = false
  		print(tables[1])
  		cd2 = true
  		for i = 1,1000 do
  			wait(0.1)
  			local rng = math.random(1,3)
  			if rng == 1 then
  				wait(0.2)
  				tables[3].BrickColor = BrickColor.Blue()
  			elseif rng == 2 then
  				wait(0.2)
  				tables[3].BrickColor = BrickColor.Black()
  			elseif rng == 3 then
  				wait(0.2)
  				tables[3].BrickColor = BrickColor.Green()
  			end
  		end
  	end
  	
  	
  	
  	end)
end

The error is this

I guess you should try removing the last “end” ?

2 Likes

It still doesn’t work, it just break the script more. I tried re-scripting and still nothing.

You are actually missing an end. at tables[2].Touched:Connect(function(player) there should be a end) for it.

local tables = {script.Parent.Door,script.Parent.Key.Union, script.Parent.Floor}
local newp = Instance.new("BoolValue")
newp.Value = false
local cd = false
local cd2 = false
for i = 1,#tables do
	tables[2].Touched:Connect(function(player)
		if cd == false then
			newp.Name = "KeyCard"
			local e = Instance.new("Part", script.Parent.Key)
			e.Name = "Union"
			e.Anchored = true
			e.Position = Vector3.new(17.468, 1, 9.816)
			tables[2]:Destroy()
			print(tables[1])
			newp.Value = true
			cd = true
			newp.Parent = workspace	
		end
	end) --You were missing this.

	tables[1].Touched:Connect(function(player2)
		if newp.Value == true and cd2 == false then
			tables[1].Transparency = 1
			tables[1].CanCollide = false
			print(tables[1])
			cd2 = true
			for i = 1,1000 do
				wait(0.1)
				local rng = math.random(1,3)
				if rng == 1 then
					wait(0.2)
					tables[3].BrickColor = BrickColor.Blue()
				elseif rng == 2 then
					wait(0.2)
					tables[3].BrickColor = BrickColor.Black()
				elseif rng == 3 then
					wait(0.2)
					tables[3].BrickColor = BrickColor.Green()
				end
			end
		end
	end)
	
end
2 Likes

You’re missing an end) for your first .Touched connection in the for i = 1,#tables do loop.

EDIT: @Kaid3n22 beat me to it lol.

2 Likes