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

Script for overhead name gui not working for no reason?

Asked by 1 year ago

Hi, this is a script which is meant to duplicate a overhead gui, and set it to appear over every players head. I have tried many things and I cant find out why it doesnt work

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
        char.Humanoid.DisplayDistanceType =     Enum.HumanoidDisplayDistanceType.None       

        local gui = game.ServerStorage.OverheadGui
        local clone = gui:Clone()
        clone.Parent = workspace
        clone.Adornee = char.Head

        local frame = clone.Frame
        local name = frame.PlrName

        name.Text = plr.Name

        print(plr.Name.." has joined - gui given!")

        while wait() do
            name.Text = plr.RpName.Value
        end
    end)
end)

Here is the issue: when testing, the gui goes above my head which my name, but doesnt go above anyone elses head with theirs. I tried it in a 2 player test server in studio and it worked for both players. Help would be much appreciated, cheers.

0
Maybe reboot studio and try it. Also try it in a normal server Not in studio theking66hayday 841 — 1y
0
put it in a server script bittyboy1234 91 — 1y

1 answer

Log in to vote
0
Answered by 1 year ago

It's probably because of CharacterAdded event not working all the time. I recommend putting the script inside StarterCharacterScripts inside StarterPlayer.

-- Normal script inside StarterCharacterScript
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")

local character = script.Parent
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
local player = Players:GetPlayerFromCharacter(character)

humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None

local gui = ServerStorage.OverheadGui
local clone = gui:Clone()
clone.Name = player.UserId
clone.Parent = character.Head
clone.Adornee = character.Head

local frame = clone.Frame
local name = frame.PlrName
local rpName = player.RpName
name.Text = (not rpName.Value:match("^%s*$")) and rpName.Value or player.Name

print(player.Name.." has joined - gui given!")

rpName:GetPropertyChangedSignal("Value"):Connect(function()
    name.Text = (not rpName.Value:match("^%s*$")) and rpName.Value or player.Name
end)
Ad

Answer this question