Im trying to create a script that changes the value on death. Please Help.
game:GetService('Players').PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) player = game.Players:GetPlayerFromCharacter(character) if player:FindFirstChild("InGame") then player.InGame:remove() character:WaitForChild("Humanoid").Died:connect(function() print(player.Name .. " has died!") game.Workspace.PeopleInGame.Value = game.Workspace.PeopleInGame.Value -1 end) end end) end)
Output: 22:11:19.638 - Workspace.PlayerHandler:8: attempt to perform arithmetic on field 'PeopleInGame' (a userdata value)
You forgot to access the 'Value' property of PeopleInGame
.
Also don't use deprecated methods
game:GetService('Players').PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) if player:FindFirstChild("InGame") then player.InGame:Destroy() character:WaitForChild("Humanoid").Died:connect(function() print(player.Name .. " has died!") game.Workspace.PeopleInGame.Value = game.Workspace.PeopleInGame.Value -1 end) end end) end)
Also, if you're only trying to get the number of people ingame, you can use the NumPlayers
property of Players.
print(game.Players.NumPlayers)