Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[Changing A Value] Died Event. UserData Value?

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)

3 comments

0

Add .Value to the second PeopleInGame Value. Instead the script is reading it like number = object - 1

0

It still isnt working

0

Get rid of line 3, It's not needed.

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.