Invalid argument #1 to 'pairs' (table expected, got Instance)

  1. What do you want to achieve? Keep it simple and clear!

I am making an automatic fire system to every house model and I want a GUI to tween and appear to the players who are already on the fire team to see this GUI. The GUI basically tells them there is a fire at a residential house.

  1. What is the issue? Include screenshots / videos if possible!

The issue is that there is an error coming up, just like in the title, that I don’t know how to fix. I have rarely or ever encountered this error.

Workspace.HOUSE1.Script:5: invalid argument #1 to 'ipairs' (table expected, got Instance)

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I tried changing the order of the script to see if that changed anything but nope.

Code

local house = script.Parent.Parent.HOUSE1
local TweenService = game:GetService(“TweenService”)

while wait(40) do
	for _, players in pairs(game.Teams["Fire Department"]) do
		local tweenInfo = TweenInfo.new(5, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, 1, 1)
		local tween = TweenService:Create(players.PlayerGui.Fire.Alert, tweenInfo, {Position = UDim2.new(0.095, 0,0.021, 0)})
		players.PlayerGui.Fire.Enabled = true
		players.PlayerGui.Fire.Alert.Text = "House fire alarm activated! Units required!"
		tween:Play()
		wait(5)
		local tweenInfo = TweenInfo.new(5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, 1, 1)
		local tween1 = TweenService:Create(players.PlayerGui.Fire.Alert, tweenInfo, {Position = UDim2.new(0.095, 0,-0.088, 0)})
		tween1:Play()
		wait(6)
		players.PlayerGui.Fire.Enabled = false
	end
	for _, parts in pairs(house:GetChildren()) do
		if parts:IsA("Part") then
			local fire = Instance.new("Fire")
			local smoke = Instance.new("Smoke")
			local alreadyBurning = parts:FindFirstChildWhichIsA("Fire")
			if not alreadyBurning then
				fire.Parent = parts
				fire.Size = 18
			end
		end
	end
end

Can anybody help?

2 Likes

game.Teams["Fire Department"]

Instead of this, try doing game:GetService('Teams')['Fire Department']:GetPlayers()

8 Likes

try this:

game.Teams[“Fire Department”]:GetChildren()

1 Like

For the first for loop, the team is a instance, not a table.

You would need to get the children of the team.

This won’t work because it’s getting the children (tools) inside my team, not the players. :GetPlayers() worked.