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

Setting a players team(In a localScript only)?

Asked by 10 years ago

I've been working on a team changer GUI

I have it teleporting you to a specific spot.... but i would love it if it could just set your team, Instead of a spawning point. so i don't have to use a one way door I also have three teams

The Local script is located at:

StarterGui -> TeamMenu(ScreenGUI) ->LocalScript(TheLocalScript)

Inside the: "TeamMenu(ScreenGUI)" ChooseBlue(TextButton),ChooseRed(TextButton),ChooseGreen(TextButton),

here is what you need to know:

ChooseBlue  =  false
ChoosenGreen = false 
ChoosenRed = false
RedTeam = "Bright red"
BlueTeam = "Really blue"
GreentTeam = "Lime green"
BlueSpot = CFrame.new(-32, 4.6, 168)
RedSpot = CFrame.new(0, 0, 0)
GreenSpot = CFrame.new(0, 0, 0)
SetTeamBlue = false
SetTeamRed = false
SetTeamGreen = false

ChooseGreen.MouseButton1Down:connect(ChoosenGreen == true)
ChooseRed.MouseButton1Down:connect(ChoosenRed == true)
ChooseGreen.MouseButton1Down:connect(ChoosenBlue == true)

while ChoosenBlue == true do
    player.Character.Torso.Anchored = true
    wait()
    player.Character.torso.CFrame = newplace
    wait()
    player.Character.Torso.Anchored = false
    wait()
    ChoosenBlue = false
    SetTeamBlue = true
end

while SetTeamBlue == true do
    --This is where you will become part of the Blue team
end

while ChoosenRed == true do
    player.Character.Torso.Anchored = true
    wait()
    player.Character.torso.CFrame = newplace
    wait()
    player.Character.Torso.Anchored = false
    wait()
    ChoosenRed = false
    SetTeamRed = true
end

while SetTeamRed == true do
    --This is where you will become part of the red team
end

while ChoosenGreen == true do
    player.Character.Torso.Anchored = true
    wait()
    player.Character.torso.CFrame = newplace
    wait()
    player.Character.Torso.Anchored = false
    wait()
    ChoosenGreen = false
    SetTeamGreen = true
end

while SetTeamGreen == true do
    --This is where you will become part of the Green team
end

I have no experience using teams with roblox and ask that when you awnser you explain what you did.

1 answer

Log in to vote
0
Answered by 10 years ago

What you did is set variables to let the code jump around and mesh pieces of code together. I consolidated the into anonymous functions, but you could do with defined functions and call those functions from the connect methods. A question, did you mean "BlueSpot" or another color's var for "newplace"?

--You didn't need these variables.
RedTeam = "Bright red"
BlueTeam = "Really blue"
GreenTeam = "Lime green" --spelling error here. You had "GreentTeam".
BlueSpot = CFrame.new(-32, 4.6, 168)
RedSpot = CFrame.new(0, 0, 0)
GreenSpot = CFrame.new(0, 0, 0)
--You didn't need these variables either.

-- The below code is consolidated somewhat.


script.Parent.ChooseGreen.MouseButton1Down:connect(function() --You only need script.Parent if you didn't set a variable for it.
    player.Character.Torso.Anchored = true
    wait()
    player.Character.torso.CFrame = newplace --What is newplace? It wasn't defined in the script you gave us. Did you mean "GreenSpot", the variable?
    wait()
    player.Character.Torso.Anchored = false
    wait()
    game.Players.LocalPlayer.TeamColor = BrickColor.new(GreenTeam) --TeamColor is a BrickColor value. I gave it the var you set earlier.
end)

ChooseRed.MouseButton1Down:connect(function()
    player.Character.Torso.Anchored = true
    wait()
    player.Character.torso.CFrame = newplace --What is newplace?
    wait()
    player.Character.Torso.Anchored = false
    wait()
    game.Players.LocalPlayer.TeamColor = BrickColor.new(RedTeam)
end)

ChooseBlue.MouseButton1Down:connect(function() -- You had "ChooseGreen" twice.
    player.Character.Torso.Anchored = true
    wait()
    player.Character.torso.CFrame = newplace --What is newplace?
    wait()
    player.Character.Torso.Anchored = false
    wait()
    game.Players.LocalPlayer.TeamColor = BrickColor.new(BlueTeam)
end)

Here's the wiki documentation on teams and on an individual team.

0
I did mean Bluespot for "newplace" just forgot to change it dlange95 15 — 10y
Ad

Answer this question