"Invalid table key type used"

Hi, I’m using this script for my hotel I am making but every time it gets to:

playerUpdate:FireAllClients(rooms)

I get an error saying the following:

12:46:25.519 - Invalid table key type used
12:46:25.520 - Stack Begin
12:46:25.520 - Script ‘ServerScriptService.Handler’, Line 31
12:46:25.521 - Stack End

The same error shows up further down in line 43. I’m not sure what the issue is, the full script is below.

local getKey = ReplicatedStorage.GetKey
local playerUpdate = ReplicatedStorage.PlayerUpdate

local rooms = {}
local playerOwned = {}

local waitTime = 2

for _, door in pairs(game.Workspace.DOORS:GetChildren()) do
	rooms[tonumber(door.Name)] = false
	door.Touched:Connect(function(hit)
		if hit.Parent:IsA("Tool") and hit.Parent.Name == door.Name then
			door.CanCollide = false
			door.Transparency = 0.5
			wait(3)
			door.CanCollide = true
			door.Transparency = 0
		end
	end)
end

getKey.OnServerInvoke = function(_, roomNum, toGive)
	if not rooms[tonumber(roomNum)] and not playerOwned[toGive] then
		local key = game.Workspace.Tool:Clone()
		key.CanBeDropped = false
		key.Name = roomNum
		key.Parent = toGive.Backpack
		rooms[tonumber(roomNum)] = toGive
		playerOwned[toGive] = tonumber(roomNum)
		playerUpdate:FireAllClients(rooms)
		return true, key
	elseif rooms[tonumber(roomNum)] then
		return false, "Room occupied by "..rooms[tonumber(roomNum)].Name
	else
		return false, "Player already has room"
	end
end

game.Players.PlayerRemoving:Connect(function(player)
	if playerOwned[player] then
		rooms[playerOwned[player]] = false
		playerUpdate:FireAllClients(rooms)
	end
end)

are you sure you can do tonumber() functions to access an index? I’d try to store the tonumber a line up as roomNumNum and then try rooms[roomNumNum]

The script works with no errors when I move it to a blank baseplate with the models I needed, so I’m not sure exactly what the issue is.