Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[Changing A Value] Died Event. UserData Value?

Asked by 9 years ago

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)

0
Add .Value to the second PeopleInGame Value. Instead the script is reading it like number = object - 1 M39a9am3R 3210 — 9y
0
It still isnt working Timster111 25 — 9y
0
Get rid of line 3, It's not needed. EzraNehemiah_TF2 3552 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

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 NumPlayersproperty of Players.

print(game.Players.NumPlayers)
Ad

Answer this question