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

textlabel dosent change in base of team, how can i fix this?

Asked by
322ita 15
4 years ago

hello im a newbie in scripting and i'm making a game and it has 3 teams i created a gui with textlabel and the text change in base of the team name , colors too but it dosent work, how can i fix it?

local player = game:GetService("Players")

        if player.Team == ("clandestin") then
            script.Parent.TextLabel.Text = player.Team.Name
            script.Parent.TextLabel.BackgroundColor3 = Color3.fromRGB(190, 71, 11)
        end
        if player.Team == ("cittadino") then
            script.Parent.TextLabel.Text = player.Team.Name
            script.Parent.TextLabel.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
        end
        if player.Team == ("controllore") then
            script.Parent.TextLabel.Text = player.Team.Name
            script.Parent.TextLabel.BackgroundColor3 = Color3.fromRGB(22, 67, 190)
end 

2 answers

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

Btw please use Lua Code Block for future questions.

local plr = game.Players.LocalPlayer
local chr = plr.Character or plr.CharacterAdded:Wait() -- makes sure player loaded in before script ran

if plr.TeamColor == "" then
    script.Parent.TextLabel.Text = ""
    script.Parent.TextLabel.TextColor = ""
elseif plr.TeamColor == "" then
    script.Parent.TextLabel.Text = ""
    script.Parent.TextLabel.TextColor = ""
elseif plr.TeamColor == "" then
    script.Parent.TextLabel.Text = ""
    script.Parent.TextLabel.TextColor = ""
end

Change TeamColor to the color of the team.

0
Btw use ElseIf after one If that's the main issue SitaruDaniel 44 — 4y
Ad
Log in to vote
0
Answered by
322ita 15
4 years ago

so i changed the script and now is

local plr = game.Players.LocalPlayer

if plr.TeamColor == "CGA Brown" then
    script.Parent.Text = "clandestin"
    script.Parent.TextColor = "CGA Brown"
elseif plr.TeamColor == "Lapis" then
    script.Parent.Text = "controllore"
    script.Parent.TextColor = "Lapis"
elseif plr.TeamColor == "Lime green" then
    script.Parent.Text = "cittadino"
    script.Parent.TextColor = "Lime green"
end

-- this script is from SitaruDaniel, credit added by 322ita--

but there is an error saying Players.322ita.PlayerGui.ScreenGui.TextLabel.Script:3: attempt to index nil with 'TeamColor'

what should i do?

0
I think it's because the player didnt get into the game when the script. Waiting for the character makes sure it has loaded in. SitaruDaniel 44 — 4y

Answer this question