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

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

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

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!

3 comments

0

It still isn't giving me any feedback on errors, and it doesn't work as well

0

Oh, I will edit my answer showing another mistake we both made.

0

Done, should work now :) @shaboogly

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