Problems with a Team-Creator GUI

I have a faction creator GUI that fires an event, and the server handler uses Instance.new("Team") to create a new team. But, I get this response:


I can’t figure out what the issue is.

Client

local event = game.ReplicatedStorage.Factions.NewTeam

script.Parent.MouseButton1Click:Connect(function()
	local teamname = script.Parent.Parent.FactionName
	local teamcolor = script.Parent.Parent.FactionColor
	wait(.1)
	event:FireServer(teamname, teamcolor)
end)

Server

local Event = game.ReplicatedStorage.Factions:WaitForChild("NewTeam")

Event.OnServerEvent:Connect(function(teamname,teamcolor)
	print(teamname)
	print(teamcolor)
	local NewTeam = Instance.new("Team")
	NewTeam.Parent = game.Teams
	NewTeam.AutoAssignable = false
	wait(.1)
	NewTeam.Name = teamname
	NewTeam.TeamColor = BrickColor.new(teamcolor)
end)

Any help is appreciated, thank you.

The first parameter of OnServerEvent is automatically the player instance who fired the event, you can’t give this yourself, maybe change

Event.OnServerEvent:Connect(function(teamname,teamcolor) 

To

Event.OnServerEvent:Connect(function(player,teamname,teamcolor)

So the arguments you fired to the server won’t be impacted by that automatic player instance? Which would explain your error

3 Likes

It works, but the team name would remain the same even though the TextButton is changed.

Screen Shot 2021-03-26 at 1.05.07 PM

What are FactionName and FactionColor in terms of things in the explorer?

FactionName is Team.Name and FactionColor is Team.Color = BrickColor.new(color)

They’re Values? May I see them in the explorer? Also, is anything changing their value?

No, their not values they’re properties. Would I have to make them values?

What do you mean “properties”? Attributes? How do they look like? And does anything even change their value?

What prints?
extra words, extra words

It prints “Faction Name” instead of the team name I put in

What changes the values of those two things?

Screen Shot 2021-03-26 at 1.12.23 PM

I mean this, properties of an object/instance

Is “Faction Name” the default value you inserted into that?

1 Like

Yes, and whatever I printed in the server script replaces the team name I typed in with the default value.

Is there any code that changes their values?

The client script, this line right here:

local teamname = script.Parent.Parent.FactionName

No no, that’s just retrieving it, is there code anywhere that updates the FactionName and the FactionColor properties?

2 Likes

No, I don’t see anything that updates it.

There’s your issue then, you need code to update it, I presume that textbox is for the name of the faction? Somewhere you could maybe try, even in the same script, to add this

local textbox = --Location of textbox

textbox:GetPropertyChangedSignal("Text"):Connect(function()
	teamname = textbox.Text
end)

So that way it’ll update when you type in that textbox, or just set teamname to the text of the Textbox when you press the button

I’d get this though.

But did I place this code correctly?

local event = game.ReplicatedStorage.Factions.NewTeam

script.Parent.MouseButton1Click:Connect(function()
	local textbox = script.Parent.Parent.FactionName
	textbox:GetPropertyChangedSignal("Text"):Connect(function()
		 teamname = textbox.Text
	end)
	event:FireServer(teamname)
end)