Spleef code isnt working

so i orginally had a script in every single tile for my spleef minigame but i wanted to change that. so when i moved it into one script with some code adjustments, the script just wasnt working

tile = script.Parent:GetChildren("Tile")

for i = 1, #tile do
	tile[i].Touched:Connect(function()
		wait(0.35)
		tile[i]:Destroy()
	end)
end
2 Likes

maybe just do:

tile = script.Parent:GetChildren("Tile")

tile.Touched:Connect(function()
		wait(0.35)
		tile:Destroy()
	end)
end

“tile” is an array, thus doing tile.Touched wouldn’t work.

1 Like

just use a for I, v in pairs()

ok ill go and try that real quick

local tile = script.Parent:GetChildren("Tile")

for i, v in pairs(tile) do
	v.Touched:Connect(function()
		wait(.35)
		v:Destroy()
	end)
end

The script works for me, are you sure there isn’t a script interfering?

yea cause it works if i just add the script into each tile

I placed a bunch of parts, grouped them together, and put that script as a child of the model instance. I didn’t put the script in each individual tile. Could you show me what your explorer (only the tiles model) looks like?

this is the error if i try it with one script:

Touched is not a valid member of Folder "Workspace.Spleef.Spawns"  -  Server  -  TileScript:4
  Stack Begin  -  Studio
 Script 'Workspace.Spleef.TileScript', Line 4  -  Studio  -  TileScript:4
 Stack End

Try adding a short bit of code that acts as a filter to sort out the non-parts.

tile = script.Parent:GetChildren("Tile")

for i = 1, #tile do
	tile[i].Touched:Connect(function()
if tile[i]:IsA("BasePart") then --checks if the touched part really is a part
		wait(0.35)
		tile[i]:Destroy()
	end)
end
end

The problem with your script isn’t actually in the script. The problem is that there is a “Spawns” folder, and as you know, folders can’t be touched.

1 Like

but i never even referred to the folder at all

wait i know why this is happening its because when its waiting for child, it has to eventually go through the folder

i just moved the tiles into the script and parented the script to the tiles and it worked

1 Like

Yep, that’s correct. You’re getting all of the children of script.Parent and eventually, the script is gonna get the folder too.

1 Like