How do I change a players team depending on the value of a string value?

Hello, I’m trying to make a tycoon, but when a player triggers a proximity prompt, their team should be set to the team that the tycoon has, in a string value. Why isn’t this working though?

-- Claim Tycoon
local Claimer = script.Parent.Claimer
local PP = Claimer.ProximityPrompt

-- Values
local TycoonValues = script.Parent.TycoonValues
local Team = TycoonValues.Team
local Owner = TycoonValues.Owner
local Claimed = TycoonValues.Claimed

-- Teams
local Teams = game:GetService("Teams")
local NoTeam = Teams["No Team"]

PP.Triggered:Connect(function(plr)
	if Owner.Value == "" then
		if Claimed.Value == false then
			if plr.Team == NoTeam then
				plr.Team = Team.Value -- issue
				
				PP.Enabled = false
				Claimer.Transparency = 1
				Claimer.CanCollide = false
			end
		end
	end
end)

error:

  Unable to assign property Team. Object expected, got string  -  Server - Main:20

The property Team inside the player is indeed an ObjectValue, thus, you can either just assign the team itself to it, or use its name for that.

Try this -

Replace this line :
plr.Team = Team.Value -- issue
with this:
plr.Team = Teams[Team.Value]

I assume ‘Team’ [your variable] is a stringvalue, so this should work
[Also, for practice, try to avoid naming variables in the same names as properties]

1 Like