Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

cant change my team to hr and others to customer. How to fix?

code:

function setTeam(player, teamName)
	player.TeamColor = game.Teams[teamName].TeamColor
	if player.Character then --Just in case the character doesn't exist for some reason
		player.Character:BreakJoints() -- Kills the players' character
	end
end

--How it's used
wait(2)
game.Players.PlayerAdded:Connect(function(plr)
	if plr.Name == "SUPERGIZMO3607" then
		setTeam(game.Players.SUPERGIZMO3607, "Hr")
	else
		setTeam(game.Players.plr.Name, "Customer")
	end
end)

i am going to try to change my team to "Hr" but everytime i join but instead it just changes me to a random team like staff or customer

3 answers

There's a lot more easier way to code this to make it a hell of a lot more complicated and more organized.

-- [[ SERVICES ]] --

Teams = game:GetService('Teams')
Players = game:GetService('Players')

-- [[ ARRAYS ]] --

local highRanks = {1, 'ROBLOX', 'builderman'}

-- [[ MAIN SCRIPT ]] --

function teamPlayer(Player, teamVariable)
	if teamVariable == 'HR' then
		Player.Team = Teams[teamVariable]
	elseif teamVariable == 'Customer' then
		Player.Team = Teams[teamVariable]
	end -- check variable
end -- function end

function onPlayerAdded(Player)
	for _,v in pairs(highRanks) do
		if type(v) == 'string' and string.lower(v) == string.lower(Player.Name) then
			teamPlayer(Player, 'HR')
			return
		elseif type(v) == 'number' and v == Player.UserId then
			teamPlayer(Player, 'HR')
		return
	end -- check type
end -- for loop
teamPlayer(Player, 'Customer')
end -- function end

-- [[ CONNECTIONS ]] --

Players.PlayerAdded:Connect(onPlayerAdded)

Well, I am going to suggest you a simpler version and editing your code.

First, you have to remove wait(2) in your code. Also, In the PlayerAdded function, there are a lot of errors.

-- On line 14
-- Your error
		setTeam(game.Players.plr.Name, "Customer") 
-- What if should be
		setTeam(game.Players[plr.Name], "Customer")

And this is how your whole code must look:

local Userid = 1234567890 -- Put your UserId here
local HRName = "SUPERGIZMO3607"

function setTeam(player, teamName)
    player.TeamColor = game.Teams[teamName].TeamColor
    if player.Character then --Just in case the character doesn't exist for some reason
        player.Character:BreakJoints() -- Kills the players' character
    end
end

game.Players.PlayerAdded:Connect(function(plr)
    if plr.UserId == Userid then -- Using UserIds' are the most optimal way
        setTeam(game.Players[HRName], "Hr")
    else
        setTeam(game.Players[plr.Name], "Customer")
    end
end)

If you don't know your UserId, while testing, go to Players and click on your name, and on your Properties tab, search for UserId.

Lemme know if it helps!

1 comment

0

Make sure you have AutoAssignable ON

Make sure you have auto-assignable off on the teams that’s you don’t want people to get automatically

This discussion is preserved as it was. New answers, comments, and votes are closed.