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

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

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

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.

1 comment

0

Btw use ElseIf after one If that's the main issue

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?

1 comment

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.

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