Team change GUI not changing team

Hey gamers,

I’m creating a team change GUI. The way it works is that a player clicks on a team from the “teams” section of the main menu, then clicks “play” to confirm their choice. I store their choice in a StringValue named “SelectedTeam”, but for some reason I always get returned “Object expected, got string.” I would appreciate it if someone can point me in the right direction. I don’t mind giving more information if I must.

Here’s the explorer:

Here are all the necessary scripts (some irrelevant things aren’t shown):

Play.Click

local plr = game:GetService("Players").LocalPlayer
local team = script.Parent.Parent.SelectedTeam.Value

wait(0.5)
script.Parent.MouseButton1Click:Connect(function()
	game:GetService("ReplicatedStorage").LoadCharacter:FireServer("plr, team")
end)

SD.Onclick

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.Parent.Parent.SelectedTeam.Value = "Security"
end)

game.ServerScriptService.LoadCharacter

local RStorage = game:GetService("ReplicatedStorage")
RStorage.LoadCharacter.OnServerEvent:Connect(function(plr, team)
	plr.Team = team
	plr:LoadCharacter()
end)
1 Like

Are you sure your SelectedTeam class is actually a StringValue not a ObjectValue?

2 Likes

Yeah, that was one of the first things I checked

Was the full error “Unable to assign property Value. Object expected, got string”? Send a screenshot of what the console shows.

Edit: Try to set a string manually to SelectedTeam and see if it will let you

Hi! I agree with @sonic_848, if the error is as you say, then the input is of object class, but you gave a string, probably means it is an object value not a string value. Seeing the line

script.Parent.Parent.Parent.Parent.SelectedTeam.Value = "Security"

most likely confirms the case. Additionally, the stringValue and objectValue objects are pretty similar, so it can be easily mixed up.

The client is sending the string “plr, team” to the RemoteEvent. The server would be receiving that player as the first argument (something that clients cannot change nor do they need to provide as the engine does that automatically) and that string as the second argument which you’ve named “team” in the server’s handler. It seems you intend to actually just provide the team instead of a string containing the names of those parameters that you’d like to be sent over the RemoteEvent.

Remove the quotes and just provide the team variable as an argument. The server will know what player fired the event in the plr parameter and the team from the team parameter that was provided as the first argument of the FireServer call done by the client.

1 Like

yes, that’s the error.

16:59:59.242  Unable to assign property Team. Object expected, got string  -  Server - LoadCharacter:3
16:59:59.242  Stack Begin  -  Studio
16:59:59.242  Script 'ServerScriptService.LoadCharacter', Line 3  -  Studio - LoadCharacter:3
16:59:59.243  Stack End  -  Studio

I have tried setting the string manually

sorry late reply btw

plr.Team expects the team object not its name.
here’s a example

plr.Team = game.Teams.????
1 Like

Like the person above said it’s actually your serverscript code.
Switch it to this:

local RStorage = game:GetService("ReplicatedStorage")
local Teams = game:GetService("Teams")

RStorage.LoadCharacter.OnServerEvent:Connect(function(plr, team)
	local FoundTeam = Teams:FindFirstChild(team)
	if not FoundTeam then return end
	
	plr.Team = FoundTeam
	plr:LoadCharacter()
end)
1 Like

worked after a couple adjustments, thanks guys!! :3

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.