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