I've been making a game with a queue system which means when players touch it, they get tagged. When the part is clicked, everybody that is tagged will be teleported to another place except there's a problem. I keep getting either an "Unable to cast value to objects" error. Here's my code:
Teleport Script (Server Script):
script.Parent.ClickDetector.MouseClick:Connect(function()
if script.Parent.Parent.PlayerCount.Value >= 26 then
script.Parent.Touch.Disabled = true
script.Parent.Parent.NameGui.TextLabel.Text = "Game is about to start..."
wait(3)
script.Parent.Parent.NameGui.TextLabel.Text = "Teleporting players..."
local tele = game:GetService("TeleportService")
local pv = game.Players:GetChildren()
local Server = tele:ReserveServer(4625879335)
for i = 1, #pv do
local value = pv[i]
if value.Teams.Value == true then
tele:TeleportToPrivateServer(4625879335,Server,value)
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
if script.Parent.Parent.PlayersJoined:FindFirstChild(plr.Name) ~= nil then
script.Parent.Parent.PlayerCount.Value = script.Parent.Parent.PlayerCount.Value - 1
end
end)
and here's the code for the tag script:
local On = true
local function debounce(func)
local isRunning = false
return function(...)
if not isRunning then
isRunning = true
func(...)
isRunning = false
end
end
end
script.Parent.Touched:Connect(debounce(function(part)
local Humanoid = part.Parent:FindFirstChild("Humanoid")
if Humanoid then
local player = game.Players:GetPlayerFromCharacter(part.Parent)
player.Teams.Value = true
end
local Play = game.Players:GetPlayerFromCharacter(part.Parent)
local Plr = Play.UserId
if script.Parent.Parent.PlayerCount.Value <= 52 and On == true then
if script.Parent.Parent.PlayersJoined:FindFirstChild(part.Parent.Name) == nil and workspace.SoloQueue.PlayersJoined:FindFirstChild(part.Parent.Name) == nil then
tag = Instance.new("StringValue")
tag.Parent = script.Parent.Parent.PlayersJoined
tag.Name = part.Parent.name
Play.Teams.Value = true
script.Parent.Parent.PlayerCount.Value = script.Parent.Parent.PlayerCount.Value + 1
end
end
end))
script.Parent.Parent.PlayerCount.Changed:Connect(function()
script.Parent.Parent.NameGui.TextLabel.Text = "Join Teams queue ("..script.Parent.Parent.PlayerCount.Value.."/52, 26 minimum, click the button to teleport players)"
end)
In line 13 on the teleport script they displayed an error saying "Unable to cast value to objects". Any suggestions?

1 comment
well you learn something new everyday. I didn't even know how tables were properly used in script. Thanks for the help.