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

Script for overhead name gui not working for no reason?

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.

2 comments

0

Maybe reboot studio and try it. Also try it in a normal server Not in studio

0

put it in a server script

1 answer

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)

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