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

My script to add scores after a player dies isn't functioning properly, why not?

Asked by 7 years ago
Players = game:GetService("Players")
Players.PlayerAdded:connect(function(Player)
    Player.CharacterAdded:connect(function(Character)
        local Humanoid = Character:WaitForChild("Humanoid")
        Humanoid.Died:connect(function()
            if Humanoid.TeamColor == "Bright blue" then
    game.Workspace.RedScore.Value = game.Workspace.RedScore.Value + 1
else
    game.Workspace.BlueScore.Value = game.Workspace.BlueScore.Value + 1
end
        end)
    end)
end)

I made this script so that whenever a player dies, it checks their team, and if it's the blue team, a number value in workspace will go up by 1, and if it's the red team, a different number value in workspace will go up by 1. I have this script in serverscriptservice and I have tried different ways, one time it worked but only the red team score increased :/ at this point it doesn't work at all and shows me no errors in the output, anyone know why?

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Explanation

In lua, == will also compare data type. Player.TeamColor will return a BrickColor(ikr damn americans). You are trying to compare that with a string.****

EDIT:

There is also another problem, Humanoid.TeamColor is not a property. You want to check Player.TeamColor

Solution

Instead of having line 6 compare Player.TeamColorwith a string like so:

if Humanoid.TeamColor == "Bright blue" then

It should compare it with the data type of TeamColor and it should be Player.TeamColor :

if Player.TeamColor == BrickColor.new("Bright blue") then

If this helped then please upvote and choose it as the answer!

0
It still isn't giving me any feedback on errors, and it doesn't work as well shaboogly123 4 — 7y
0
Oh, I will edit my answer showing another mistake we both made. User#15029 30 — 7y
0
Done, should work now :) @shaboogly User#15029 30 — 7y
Ad

Answer this question