Hi, I'm trying to make a block of code where when the player touches a brick it removes them from the "PlayersToKill" table. But when I run the code I get this error. bad argument #2 (number expected, got Object) on line 21. I'm not sure what this means or how to fix it but if somebody could help me that would be great!
game.ReplicatedStorage.Events.TeleportToCafe.OnServerEvent:Connect(function()
PlayersToKill = {}
for i,v in pairs(game.Players:GetPlayers()) do
Player = v
table.insert(PlayersToKill,Player)
end
local debounce = false
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if debounce == false then
if game.ReplicatedStorage.CanTeleportToCafe.Value == true then
debounce = true
game.ReplicatedStorage.Events.TeleportScreen:FireClient(Player)
wait(0.7)
local HumanRootPart = hit.Parent:FindFirstChild("HumanoidRootPart")
HumanRootPart.CFrame = CFrame.new(game.Workspace.Cafe.Position + Vector3.new(0,3,0))
print("Teleported")
table.remove(PlayersToKill,Player)
wait(1)
debounce = false
end
end
end
end)
wait(7)
for i,v in pairs(PlayersToKill) do
local Player = v
for i,v in pairs(game.Workspace:GetChildren()) do
if v:IsA("Model") and v.Name == Player.Name then
local SecondPlayer = v
SecondPlayer.Humanoid.Health = 0
end
end
end
end)
