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

Why does this script not work?

Asked by
Sir_Melio 221 Moderation Voter
9 years ago
01-- "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.
02-- LocalScript
03player = game.Players.LocalPlayer
04 
05while wait() do
06    if player.Character.Humanoid.Health == 0 then
07        if player.TeamColor == "Bright red" then
08            Use("Droid")
09        else
10            Use("Human")
11        end
12        wait(5)
13    end
14end

1 answer

Log in to vote
0
Answered by
DevChris 235 Moderation Voter
9 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:

01local player = game.Players.LocalPlayer
02local character = player.Character
03if not character or not character.Parent then
04    character = player.CharacterAdded:wait()
05end
06local humanoid = character:WaitForChild('Humanoid')
07 
08humanoid.Died:connect(function()
09    -- code
10end)
Ad

Answer this question