For some reason it doesn’t work, doesn’t even show up. I’ve tried another script which was just 3 lines, but it wouldn’t stop moving around when I zoomed out or jumped around, even if I attached it to the HumanoidRootPart, so I tried this instead I got of a YT tutorial. But not even this works. Does anyone know what might be wrong?
local Players = game:GetService("Players")
local connections = {}
local overHeadTemplate = script.OverHeadGui
Players.PlayerAdded:Connect(function (player)
connections [player] = player.CharacterAdded:Connect(function (character)
local NewOverHead = overHeadTemplate:Clone()
NewOverHead.PlayerName.Text = player.Name
NewOverHead.Parent = character:WaitForChild("HumanoidRootPart")
end)
end)
Players.PlayerRemoving:Connect(function (player)
if connections[player] then
connections[player]:Disconnect()
connections[player] = nil
end
end)
Remove the PlayerAdded function, CharacterAdded function, and PlayerRemoving function
Put the UI inside ReplicatedStorage
And put this Script inside StarterCharacterScripts
Server:
local p = game.Players -- Players
local char = script.Parent -- The Character
local plr = p:GetPlayerFromCharacter(char) -- Gets the LocalPlayer from the Character
local OHT = game.ReplicatedStorage.OverHeadGui:Clone() -- Clones UI
OHT.Parent = char:WaitForChild("HumanoidRootPart") -- Parents the UI
OHT.PlayerName.Text = plr.Name -- Applies Name to text
script:Destroy()
local overHeadTemplate = game:GetService("ServerStorage").OverHeadGui --try puttin your overhead gui here in server storage
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
local Player_overhead = overHeadTemplate:Clone() --clones the overhead gui
player.Character:WaitForChild("Humanoid").DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None -- sets the default nametag to none so no one sees it
Player_overhead.Frame.PlayerName.Text = player.DisplayName -- or player.Name if you want the username
Player_overhead.Parent = player.Character:WaitForChild("HumanoidRootPart") --parents it to the humanoid
end)
end)
Try to wait until the character’s parent is not nil before getting the character’s root part:
repeat task.wait() until Character.Parent ~= nil
and put the code that is in the character added function inside a task.defer()
Also, I’d recommend you set the adornee of the billboard gui not just parenting it to a character part…
Final code should be something like that:
local Players = game:GetService("Players")
local connections = {}
local overHeadTemplate = script.OverHeadGui
Players.PlayerAdded:Connect(function (player)
connections [player] = player.CharacterAdded:Connect(function (character)
repeat task.wait() until character.parent ~= nil
task.defer(function()
local NewOverHead = overHeadTemplate:Clone()
local Target = character:WaitForChild("HumanoidRootPart")
NewOverHead.PlayerName.Text = player.Name
NewOverHead.Adornee = Target
NewOverHead.Parent = Target
end)
end)
end)
Players.PlayerRemoving:Connect(function (player)
if connections[player] then
connections[player]:Disconnect()
connections[player] = nil
end
end)
side note… the rootpart is not your best option for the overhead to be placed in or to be the adornee, use the character’s head instead.