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

Problems with GUI Team Changer made in a LocalScript. Any help?

local player = game.Players.LocalPlayer
local screenGui = Instance.new("ScreenGui")
screenGui.Parent = script.Parent

local frame = Instance.new("Frame")
frame.Parent = screenGui
frame.Position = UDim2.new(0, 0, 0.5, -10)
frame.Size = UDim2.new(0, 20, 0, 20)

local textButton = Instance.new("TextButton")
textButton.Parent = screenGui
textButton.Position = UDim2.new(0, 0, 0.5, -10)
textButton.Size = UDim2.new(0, 20, 0, 20)
textButton.BackgroundColor3 = BrickColor.Black().Color
textButton.TextColor3 = BrickColor.White().Color
textButton.Text = ">"

textButton.MouseButton1Down:connect(function()
	local frame = Instance.new("Frame")
	frame.Parent = screenGui
	frame.Position = UDim2.new(0.5, -150, 0.5, -225)
	frame.Size = UDim2.new(0, 300, 0, 450)

	local textButton = Instance.new("TextButton")
	textButton.Parent = screenGui
	textButton.Position = UDim2.new(0.5, -150, 0.5, -225)
	textButton.Size = UDim2.new(0, 300, 0, 50)
	textButton.BackgroundColor3 = BrickColor.Black().Color
	textButton.TextColor3 = BrickColor.White().Color
	textButton.Text = "trying to make a teamchanger (title would go here)"

--^ should be text label but as it is intended to do nothing it shouldn't matter much.

	local textButton = Instance.new("TextButton")
	textButton.Parent = screenGui
	textButton.Position = UDim2.new(0.5, -150, 0.5, -175)
	textButton.Size = UDim2.new(0, 300, 0, 50)
	textButton.BackgroundColor3 = BrickColor.Black().Color
	textButton.TextColor3 = BrickColor.White().Color
	textButton.Text = "Team"
	
	--Plus more teams.

The current script looks like that. Basically I make a ScreenGui, then a frame and then two textButtons. It basically should work like this: small button in the middle left of the screen, you press it, a gui opens up with team choices, you choose the team, click on it, respawn in that team with the gui back to it's small state. Everything is in one LocalScript

I know how to make the team change happen which would be

script.Parent.MouseButton1Click:connect(function()
player.TeamColor = BrickColor.new('(team color here)')
	player:LoadCharacter()

but the GUI doesn't show up when I add that. And yes, I could make it more simple but then it would take up more screen space.

2 answers

There are a number of mistakes here, and I have some tips for you Mistake #1: Instance.new("ScreenGui") Now, it should be apostrophes, not quotation marks. Secondly if you want it to have a parent, you name it right then and there. Example:

Instance.new('ScreenGui',game.Workspace)

That was most of what's wrong with the entire script.

3 comments

0

It actually doesn't matter whether its quotation marks or apostrophes.

0

But the tip was useful :)

0

His script was fine with how it set the GUI's parent properties; also, whether what quotation marks he used, they'll work: lua is very flexible in that kind of category.

The thing with LoadCharacter is that it can only be called from the server. This means that if you try to use it in a localscript, it will not work.

You could set up a RemoteEvent like so:

Script in ServerScriptService;

local Event = Instance.new("RemoteEvent", game.ReplicatedStorage)
Event.Name = "Respawn"

Event.OnServerEvent:connect(function(plr)
	plr:LoadCharacter()
end)

And add this bit of code to where it goes in your localscript;

local Event = game.ReplicatedStorage:WaitForChild("Respawn")

script.Parent.MouseButton1Click:connect(function()
	player.TeamColor = BrickColor.new('(team color here)')
    	Event:FireServer()
end

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