New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Why does this script not work?

Asked by
Sir_Melio 221 Moderation Voter
3 years ago
-- "Use()" is a function that does work, although the script recognizing which team the player is in does not work for some reason, it gets to the "else" instead.
-- LocalScript
player = game.Players.LocalPlayer

while wait() do
    if player.Character.Humanoid.Health == 0 then
        if player.TeamColor == "Bright red" then
            Use("Droid")
        else
            Use("Human")
        end
        wait(5)
    end
end

1 answer

Log in to vote
0
Answered by
DevChris 235 Moderation Voter
3 years ago

BrickColors are not strings. They are their own DataTypes:

if player.TeamColor == BrickColor.new('Bright red') then

Also, you don't need to use a loop for that. This is much more efficient:

local player = game.Players.LocalPlayer
local character = player.Character
if not character or not character.Parent then
    character = player.CharacterAdded:wait()
end
local humanoid = character:WaitForChild('Humanoid')

humanoid.Died:connect(function()
    -- code
end)
Ad

Answer this question