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 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)
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
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.
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
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)