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

[Answered] Team GUI, help?

Asked by 9 years ago

Alright so I'm a horrible horrible scripter, and I'm just starting out really. Here is the script I put together.

T = game.Teams.Parent.Name

function Teamon()
script.Parent.Text = UDim2.new("Your Team: ")..T()
end

This script is suppose to show the player what team they're on. Could someone give me pointers to fix my mistakes?

1
You need to slow down. WHY are you putting each word of this script down? Throwing things down that "look" like Lua is NEVER a way to write a script. BlueTaslem 18071 — 9y
0
Yeah I really need more practice. :l RawDevelopment 5 — 9y

1 answer

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

You define T as a name, but you use it as a function (line 4).

Properly, it's probably either the team object itself (without the name) or just the name. It might be better to use the Team object itself in case later you wanted to get more information (like the color).

I'm assuming this is in a TextLabel in the StarterGui (PlayerGui).

In that case, the Parent of the TextLabel is probably a ScreenGui, and its parent is probably the PlayerGui; its parent is the Player.

Players are not children of their respective teams - they are children of the Players service.

You figure out which team they are on by matching their TeamColor to a Team object's team color:

player = script.Parent.Parent.Parent.Parent
teamColor = player.TeamColor

allTeams = game:GetService("Teams"):GetChildren()
-- all the children of the Teams service

for _, team in pairs( allTeams)  do
    -- For each team,
    if team.TeamColor = teamColor then
        -- if its TeamColor matches mine,
        myTeam = team
        -- then it (team) is my team.
    end
end

myTeam now refers to the player's team.


When we set Text, we remember that Text is a string. "Your Team: " is a string. It is not a UDim2.

script.Parent.Text = "Your Team: " .. myTeam.Name
1
Thanks for your help, I have a clearer sense of scripting now. The wiki really confuses me. :l RawDevelopment 5 — 9y
1
For future reference - I hope you come back - the most helpful question on a post should be marked as "accepted" by the question asker. It helps mark threads as resolved so that they can be locked and answerers can better focus their energies BlueTaslem 18071 — 9y
Ad

Answer this question