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

How to fix this bit of code about a name gui that is in accordance with your current team?

I am trying to make a name gui that gets applied based on your team, like if you on a team named "blue", that would go over your head with the assigned color. I've been trying to make this for a few days now and I am becoming very frustrated, can I have some help? This is my code so far:

local teams = game:GetService('Teams')
game.Workspace.ChildAdded:Connect(function(name)
	if game.Players:FindFirstChild(name.Name) == nil then return end
	local GUI = game.ReplicatedStorage.NameGUI:Clone()
	GUI.NameLabel.Text =  " ".. teams.name .." "
	GUI.Parent = name.Head
end)

also note: I am new to scripting

1 answer

do it like this:

local Players = game:GetService("Players");
Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		if not (player.Team and not player.Neutral) then return end --if player is not on any team
		local nameGui = game.ReplicatedStorage.NameGUI:Clone();
		nameGui.NameLabel.Text = player.Team.Name;
		nameGui.NameLabel.TextColor = player.Team.TeamColor
	end)
end)

this will will listen for when a player's character is added to the game,it checks if the player has a team associated with them, if so, then it clones the gui in ReplicatedStorage, and makes it' text the name of the player's team, and the text color to be the color of the player's team

sharpen your coding skills here:

alvinblox;

Developer Hub

5 comments

0

I tried that but nothing happened, and I don't know why, everything seems to line up.

0

check in the output and see if there's any errors

0

where would I check that? Again Im relativity new to scripting and dont know a lot about it.

0

wait never mind, I found it and there was an error, and I fixed it but the script is still not working

0

do you have team objects in the Team service? with AutoAssignable set to true?

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