How can I change an Instance into a string?

So basically I want to change the player’s team in the server based on what character they chose during the intermission.

I put a for loop to loop through all of the players. First, it will detect if the player hasn’t chosen a character and wait for them to choose one. (It should be impossible if they don’t, but just in case.) Then it will change the player’s team to what they chose. I also put in a separate script to automatically reset the player on team change.

Here is the script I used. I might add more because I’m not finished with it:

for i, v in pairs(players:GetChildren()) do
	status.Value = "Game starting..."
	if v.Backpack.CharacterChosen == "" then
		status.Value = "Error: Everybody must choose a character."
		repeat wait() until v.Backpack.CharacterChosen ~= ""
	end
	v.Team = game.Teams[v.Backpack.CharacterChosen] -- Error here
end

It returns an error saying it expected a string for the team, but got an instance instead.

So basically “v.Backpack.CharacterChosen” is equal to the team I want to put the player in, but it wants me to put a string. How can I do that?

The error is occurring there because you’re giving the string an object value. Instead, you should try getting the CharacterChosen.Name:

v.Team = game.Teams[v.Backpack.CharacterChosen.Name]

Or…like you said in the post below mine:

v.Team = game.Teams[v.Backpack.CharacterChosen.Value]

1 Like

Oh Thanks! The CharacterChosen is a StringValue by the way, so I used .Value instead.

I’m wondering why I didn’t think of that.

1 Like