local playerlist = game.Players:GetChildren()
local dmg = {10}
local metatable = {}
metatable.__add = function(t, t2)
for i, v in pairs(t) do
local character = v.Character or v.CharacterAdded:Wait()
local humanoid = character:FindFirstChild("Humanoid")
humanoid.Health += -t2[1]
end
return "Damaged"
end
local function UpdatePlayers()
playerlist = game.Players:GetChildren()
end
game.Players.PlayerRemoving:Connect(function()
UpdatePlayers()
setmetatable(playerlist, metatable)
print(playerlist + dmg)
end)
Seems like this is being caused by your CharacterAdded:Wait(), the engine isn’t going to wait to clean up a player instance so your code can finish running.
To put it simply, your code is attempting to yield and delay the C code that is trying to clean up the player instance which the engine obv doesn’t like. To fix this just don’t yield in your __add metamethod, or just don’t call it when a player is leaving.
New response: pretty sure you can’t yield in metamethods