Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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

Log in to vote
0
Answered by
pwx 1581 Moderation Voter
4 years ago
Edited 4 years ago

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)
Ad
Log in to vote
0
Answered by 4 years ago

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!

0
Make sure you have AutoAssignable ON BestCreativeBoy 1395 — 4y
Log in to vote
0
Answered by 4 years ago

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

Answer this question