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

Name and group rank over head?

so i have a group rank over head script, but how would i make it state what the player's name is?

groupid = 3309505 --Change this to your group ID.

game.Players.PlayerAdded:connect(onPlayerRespawned)--(Do not chang)--
function onPlayerRespawned(newPlayer)
	wait(1)
	if newPlayer:IsInGroup(groupid) then
		gui=Instance.new("BillboardGui")
		gui.Parent=newPlayer.Character.Head
		gui.Adornee=newPlayer.Character.Head
		gui.Size=UDim2.new(3,0,1.25,0)
		gui.StudsOffset=Vector3.new(0,3,0)
		texta=Instance.new("TextBox")
		texta.Size=UDim2.new(1,0,1,0)
		texta.BackgroundTransparency = 1
		texta.TextScaled = true
		texta.TextColor3 = Color3.new(255, 255, 255)
		texta.Text = ("- " .. newPlayer:GetRoleInGroup(groupid) .. " -")
		texta.Parent=gui
		w = game.Lighting.WepsGroup:GetChildren()
		for i = 1,#w do
			w[i]:Clone().Parent = newPlayer.Backpack
		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 comment

0

your functions and calling are a mess

2 answers

-- You should just put this in StarterCharacterScripts (LocalScript).
	-- When your player loads, this script will load in your character.

-- Make your variables local, unless they have to be global.
local groupid = 3309505 --Change this to your group ID.



local me = game.Players.LocalPlayer
local character = me.Character
-- Use WaitForChild() on children.
local head = character:WaitForChild("Head")
local backpack = me:WaitForChild("Backpack")
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local weps = ReplicatedStorage:WaitForChild("WepsGroup")

-- If FilteringEnabled is on and you want others to see this
	-- you're going to have to utilize RemoteEvents/Functions
local gui = Instance.new("BillboardGui") 
gui.Adornee = head
gui.StudsOffset=Vector3.new(0,2,0)
local texta = Instance.new("TextBox")
texta.BackgroundTransparency = 1
texta.TextScaled = true
texta.TextColor3 = Color3.new(255, 255, 255)
-- Wiki string.format()
	-- %s is replaced
texta.Text = (string.format("- %s: %s -",me.Name,  me:GetRoleInGroup(groupid)))
-- You need to set it to something first
texta.Size = UDim2.new(0,200,0,10)
texta.Parent=gui
-- Parent source GUI before using Textbounds.
gui.Parent = head

-- Textbounds doesn't work until after you parent it
gui.Size = UDim2.new(1.5,0,1.5,1)
-- Use textbounds to get the correct size
-- Using Scale vs offset prevents the zoom from moving the GUI and making it bigger
texta.Position = UDim2.new(-2.05, -(texta.TextBounds.X/2), 0,0)
texta.Size = UDim2.new(5, texta.TextBounds.X, 1,0)
	
-- Don't store stuff in Lighting.
-- Use ReplicatedStorage if you need the client to access it (LocalScripts)
-- User ServerStorage if only ServerScripts need to access it.

--[[
local w = game.Lighting.WepsGroup:GetChildren()
for i = 1,#w do
	-- gui.backpack?
		-- Do you mean the users backpack?
    w[i]:Clone().Parent = gui.Backpack
end
--]]
for i,v in pairs(weps:GetChildren()) do 
	v:Clone().Parent = backpack
end



I'll just edit your coding, as I don't have the time to recreate it.

groupid = 3309505 --Change this to your group ID.

game.Players.PlayerAdded:connect(onPlayerRespawned)--(Do not chang)--
function onPlayerRespawned(newPlayer)
    wait(1)
    if newPlayer:IsInGroup(groupid) then
        gui=Instance.new("BillboardGui")
        gui.Parent=newPlayer.Character.Head
        gui.Adornee=newPlayer.Character.Head
        gui.Size=UDim2.new(3,0,1.25,0)
        gui.StudsOffset=Vector3.new(0,3,0)
        texta=Instance.new("TextBox")
        texta.Size=UDim2.new(1,0,1,0)
        texta.BackgroundTransparency = 1
        texta.TextScaled = true
        texta.TextColor3 = Color3.new(255, 255, 255)
        texta.Text = ("- " .. newPlayer:GetRoleInGroup(groupid) .. " - "..newPlayer.Name.. " -")
        texta.Parent=gui
        w = game.Lighting.WepsGroup:GetChildren()
        for i = 1,#w do
            w[i]:Clone().Parent = newPlayer.Backpack
        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)

Thats how it should work, however I tested it in studio and It automatically states your players name, not your rank..

When I have more time I'll update it thoroughly.

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