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

How make change the name shown on the players tab?

Asked by 4 years ago

I'm creating a Role-playing game for my friends and I am thinking if it's possible when players join in the game, the names showed on the player tab list could be pre-set using a local script.

Below shows my local script, but i don't know where to change to make it work. Any help would be great :3 Thanks!

local players = game:GetService("Players")
local frame = script.Parent.Frame
local slots = frame.slots
local temp = frame.Template
local name = "AssortedCrystal15"

local players_table = {}


local dir = "Out"
local style = "Quad"
local dur = 0.5

--< functions

local function cleanup(slot)

    -- repeat wait until the slot finishes tweening
    repeat
        wait()
    until slot.Position.X.Offset == 400
    slot:Destroy()

end

local function remove(leaving)

    -- check if a player is leaving
    if leaving then

        -- if so, delete dictionary entry 
        players_table[leaving] = nil
        -- tween player slot out
        local slot = slots:FindFirstChild(leaving)
        slot:TweenPosition(UDim2.new(0, 400, 0, slot.Position.Y.Offset), dir, style, dur, true)

        -- delete the slot once it finishes (coroutine)
        local cor = coroutine.wrap(cleanup)
        cor(slot)

    end
end

local function add()

    -- loop through players
    local chil = players:GetChildren()
    for c = 1, #chil do

        -- check if present in dictionary
        if players_table[chil[c].Name] == nil then

            -- add to dictionary
            players_table[name] = 1

            -- create a slot in the list
            local slot = temp:Clone()

                -- edit that slot
                slot.Name = name
                slot.Text = name
                slot.Parent = slots
        end
    end
end

local function adjust(leaving)

    -- add() and remove()
    add()
    remove(leaving)

    local count = 0
    -- loop through players_table
    for key, value in pairs(players_table) do
    count = count + 1
        -- find corresponding slots
        local slot = slots:FindFirstChild(key)

        -- tween slot positions
        local ypos = 30 + (25+2)*(count-1)  
        slot:TweenPosition(UDim2.new(0, 0, 0, ypos), dir, style, dur, true)

    end         
end

--< events

-- player added event
players.PlayerAdded:connect(function()
    adjust(nil)
end)

-- player removing event
players.PlayerRemoving:connect(function(leaving)
    adjust(leaving.Name)
end)
0
Have you tried using leaderstats? H_exadecimal 9 — 4y
0
not really, would need explaining how that works. AssortedCrystal115 2 — 4y

Answer this question