Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Creating safe zones with using GetChildren?

Tried making a safezone script with getchildren but i get a error

ServerScriptService.Safezone:6: attempt to index number with 'Touched'


local SafeZoneFolder = workspace:WaitForChild("SafeZones")
local SafeZones = SafeZoneFolder:GetChildren()

for i = 1, #SafeZones do
	SafeZones.Touched:Connect(function()
		print("PlrTouchedSafeZone")
	end)
end

1 answer

✓ Accepted answer

Simple! You are attempting to index the table with GetChildren()! Instead you should do a different type of loop and use the value provided, like so!:

local SafeZoneFolder = workspace:WaitForChild("SafeZones")
local SafeZones = SafeZoneFolder:GetChildren()

for i,v in pairs(SafeZones) do
    v.Touched:Connect(function()
        print("PlrTouchedSafeZone")
    end)
end

This discussion is preserved as it was. New answers, comments, and votes are closed.