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

How do I target a player in a script and change the variable used depending on the team?

Hello!

I tried adjusting a script that I found to fit my needs, but I don't know how to make it work. I'd like to make it so, depending on the players team, the different ID would be used.

For example, if the player is on the Bright yellow team, he'd have the "clothingstoreid" used and displayed above his head, but if he's on the Bright blue team, he'd have the "officeid" id used.

How would I do this? The place is filtering enabled.

Thanks in advance!

clothingstoreid = 3324859  --Write your group's id right here, you don't need to worry about anything else, unless you plan on changing colors.
officeid = 2989165
familyid = 0
restuarantid = 0
game.Players.PlayerAdded:connect(onPlayerRespawned) --Connection for the function right below.
function onPlayerRespawned(newPlayer) --When a player joins the "Players" service.
    wait(1) --Obviously waits to start the script
    if newPlayer then --Just checking if the player exist.
        gui=Instance.new("BillboardGui") --Creating a new BillboardGui
        gui.Parent=newPlayer.Character.Head --Inserting the BillboardGui into the player.
        gui.Adornee=newPlayer.Character.Head
        gui.Size=UDim2.new(4,0,2,0) --Leave this one be.
        gui.StudsOffset=Vector3.new(0,3,0) --Leave this one be.
        texta=Instance.new("TextBox") --Creating a new TextBox
        texta.Size=UDim2.new(1,0,1,0) --Leave this one be.
        texta.BackgroundTransparency = 1 --1 Makes the background invisible, 0 will show it.
        texta.Text = ("[ " .. newPlayer:GetRoleInGroup(clothingstoreid) .. " ]") --This changes the text to the rank in a group.
        texta.TextColor3 = Color3.new(50,10,255) --This is the text color of non-group members.(50,10,255) is white; (0,2,44) is teal
        texta.Parent=gui --Inserting the TextBox to the BillBoardGui
        if newPlayer:IsInGroup(clothingstoreid) then --Checking if the player actually belongs to the group.
            texta.TextColor3 = Color3.new(50,10,255) --This is the text color of group members.(0,0,128) is blue;(23/255,14/255,80/255) is dark purple
        end
    end
end

function onPlayerEntered(newPlayer)
    newPlayer.Changed:connect(function (property)
        if (property == "Character") then
            onPlayerRespawned(newPlayer)
        end
    end)
end

game.Players.PlayerAdded:connect(onPlayerEntered)

1 answer

✓ Accepted answer

Try this out. [edited]


clothingstoreid = 3324859  
officeid = 2989165
familyid = 0
restuarantid = 0



function onPlayerRespawned(newPlayer) 

    wait(1)

        local gui=Instance.new("BillboardGui")
        gui.Parent=newPlayer.Character.Head
        gui.Adornee=newPlayer.Character.Head
        gui.Size=UDim2.new(0,100,0,50)
        gui.StudsOffset=Vector3.new(0,3,0)
        local texta=Instance.new("TextBox")
        texta.Size=UDim2.new(1,0,1,0)
        texta.BackgroundTransparency = 1 
        texta.TextColor3 = Color3.new(50,10,255)
        texta.Parent=gui

        if newPlayer.TeamColor == BrickColor.Yellow() then

            texta.Text = ("[ " .. newPlayer:GetRoleInGroup(clothingstoreid) .. " ]")
            if newPlayer:IsInGroup(clothingstoreid) then
              texta.TextColor3 = Color3.new(50,10,255)
            end
        elseif newPlayer.TeamColor == BrickColor.Blue() then

            texta.Text = ("[ " .. newPlayer:GetRoleInGroup(officeid) .. " ]")
            if newPlayer:IsInGroup(officeid) then
              texta.TextColor3 = Color3.new(0,0,128)
            end
		else
			gui:Destroy()
        end
    end


game.Players.PlayerAdded:connect(onPlayerRespawned) 



5 comments

0

"Attempt to connect failed: Passed value is not a function" "attempt to call a nil value"

0

What line is that on?

0

Doesn't let me click on it.

0

Ok now try

0

There's no errors, but there's no Gui's either now.

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