Attempt to index nil with 'Team' (again)

Hey gamers, I’m attempting to make the player switch teams by referencing a string value upon clicking a button (the player chooses their team elsewhere, this selection is then stored in the string value as the team name). I attempted to apply fixes but I got the same error, Players.Fox_2042.PlayerGui.Menu.Buttons.Play.Click:5: attempt to index nil with 'Team'.

here’s the script:

local plr = game:GetService("Players").LocalPlayer
local Teams = game:GetService("Teams")

script.Parent.MouseButton1Click:Connect(function(plr)
	plr.Team = Teams[script.Parent.Parent.SelectedTeam.Value]
	plr:LoadCharacter()
end)

What you are doing isnt going to work considering (and dont quote me) but you are acting like Teams is a dictionary, which it isnt (again dont quote me), maybe try this?

plr.Team = Teams:FindFirstChild(script.Parent.Parent.SelectedTeam.Value)

just remove the player variable from the function like this

local plr = game:GetService("Players").LocalPlayer
local Teams = game:GetService("Teams")

script.Parent.MouseButton1Click:Connect(function() -- here
	plr.Team = Teams[script.Parent.Parent.SelectedTeam.Value]
	plr:LoadCharacter()
end)

Oh yeah thats probably the problem. Nice job. Ignore me lol

1 Like

Your script totall fine but. i think i gonna try rescript actually
Value should be ObjectValue not StringValue

You only can change team by object or BrickColor

I tried this before but it didn’t work. Funnily enough adding ‘plr’ here was the solution to this exact problem a few hours ago

I get the error Players.Fox_2042.PlayerGui.Menu.Buttons.Play.Click:5: invalid argument #2 (string expected, got Instance)

local plr =script.Parent.Parent.Parent.Parent

script.Parent.MouseButton1Click:Connect(function()
	plr.Team=script.Parent.Parent.SelectedTeam.Value
	plr:LoadCharacter()
end)

Its should be how replace script but dont forget replace Value classname to ObjectValue