When I load into the game in studio or in the actual game, the BGUI is not inside my head and nor is is visible. I also have a script that relies on the BGUI and it’s telling me that UserInformation is not a vaild child in meshpart head
Not sure what’s going on here… (I switched from HumaniodRP to Head and now it wont work)
Server Script:
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local GameDataModule = require(game.ReplicatedStorage.Modules.GameDataModule)
local RankDataModule = require(game.ReplicatedStorage.Modules.RankDataModule)
local OverheadTemplate = script.UserInformation
local Connections = {}
Players.PlayerAdded:Connect(function(Player)
Connections[Player] = Player.CharacterAdded:Connect(function(Character)
local NewOverhead = OverheadTemplate:Clone()
local PlayerIsInGroup = Player:IsInGroup(GameDataModule.GroupID)
if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, GameDataModule.Gamepass_Premium) then
NewOverhead.Main.Tags.Premium.Visible = true
NewOverhead.Main.Tags.Visible = true
end
if PlayerIsInGroup then
--[[if Player:GetRankInGroup(GroupId) == RankDataModule.Developer then
NewOverhead.Main.PlayerRank.Rank.Text = "🛠️ "..Player:GetRoleInGroup(GroupId)
elseif Player:GetRankInGroup(GroupId) == RankDataModule.StaffAssistant or Player:GetRankInGroup(GroupId) == RankDataModule.ManagementTeam or Player:GetRankInGroup(GroupId) == RankDataModule.AdministrationTeam then
NewOverhead.Main.PlayerRank.Rank.Text = "🛡️ "..Player:GetRoleInGroup(GroupId)
else]]
NewOverhead.Main.PlayerRank.Rank.Text = Player:GetRoleInGroup(GameDataModule.GroupID)
--end
else
NewOverhead.Main.PlayerRank.Rank.Text = "Customer"
end
Character:WaitForChild("Humanoid").DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
NewOverhead.Parent = Character:WaitForChild("Head")
end)
end)
Players.PlayerRemoving:Connect(function(Player)
if Connections[Player] then
Connections[Player]:Disconnect()
Connections[Player] = nil
end
end)
local AFK = game.ReplicatedStorage.Events.RemoteEvents:WaitForChild("AFK")
AFK.OnServerEvent:Connect(function(Player, AFKDebounce)
local Character = Player.Character or Player.CharacterAdded:Wait()
local Status = Character:WaitForChild("Head").UserInformation.Main.Statuses
if AFKDebounce == true then
Status.AFK.Visible = true
Status.Visible = true
elseif AFKDebounce == false then
Status.AFK.Visible = false
Status.Visible = false
end
--[[Status.AFK.Visible = AFKDebounce and true or false
Status.Visible = AFKDebounce and true or false]]
end)
Have you tried resetting your character? If not, try it to see if the GUI loads in afterwards.
If it does, then the problem is that the CharacterAdded function is being connected after the character is already loaded in.
The best way to fix this would be to define the CharacterAdded function (it’s currently undefined), connect it, then call it again on the existing character. That would look something like this:
--define the function so you can refer to it later
local function onCharacterAdded(Character)
--code within your current CharacterAdded function would go here
end
--define the existing character (or wait for it if it doesn't exist)
local Character = Player.Character or Player.CharacterAdded:Wait()
--connect the function to the character being added
Connections[Player] = Player.CharacterAdded:Connect(onCharacterAdded)
--run the function with the current character
onCharacterAdded(Character)
If this is confusing to you, I can clear up any questions you have regarding how this would work.
Alternatively, if you just want a quick and easy fix without having to move around a lot of code, you can likely fix this with just one line right after the end) for the CharacterAdded function:
Player:LoadCharacter()
This will reload the character right after the function is connected and should also fix the issue. I personally advise against this method, but it would fix your issue nonetheless.
try something like this I believe the issue is the character is already in game before you function is setup this is common issue developers have thinking the function will fire everytime when they player enters the game
some of the things that can cause this is the modules you require at the top of the script here can delay/yeild it before making the connection to the playeradded function if this is the case even the code below won’t setup character right, but you can test this now by resetting
also the connections should be disconnected auto on player leaving
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local GameDataModule = require(game.ReplicatedStorage.Modules.GameDataModule)
local RankDataModule = require(game.ReplicatedStorage.Modules.RankDataModule)
local OverheadTemplate = script.UserInformation
local Connections = {}
function SetupCharacter(Player)
local Character = Player.Character
local NewOverhead = OverheadTemplate:Clone()
local PlayerIsInGroup = Player:IsInGroup(GameDataModule.GroupID)
if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, GameDataModule.Gamepass_Premium) then -- might want to wrap this with pcall incase of error
NewOverhead.Main.Tags.Premium.Visible = true
NewOverhead.Main.Tags.Visible = true
end
if PlayerIsInGroup then
--[[if Player:GetRankInGroup(GroupId) == RankDataModule.Developer then
NewOverhead.Main.PlayerRank.Rank.Text = "🛠️ "..Player:GetRoleInGroup(GroupId)
elseif Player:GetRankInGroup(GroupId) == RankDataModule.StaffAssistant or Player:GetRankInGroup(GroupId) == RankDataModule.ManagementTeam or Player:GetRankInGroup(GroupId) == RankDataModule.AdministrationTeam then
NewOverhead.Main.PlayerRank.Rank.Text = "🛡️ "..Player:GetRoleInGroup(GroupId)
else]]
NewOverhead.Main.PlayerRank.Rank.Text = Player:GetRoleInGroup(GameDataModule.GroupID)
--end
else
NewOverhead.Main.PlayerRank.Rank.Text = "Customer"
end
Character:WaitForChild("Humanoid").DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
NewOverhead.Parent = Character:WaitForChild("Head")
end
Players.PlayerAdded:Connect(function(Player)
SetupCharacter(Player) -- Initial setup
Player.CharacterAdded:Connect(function(Character) -- this doesn't always fire sometimes your character maybe already in game before function connected
SetupCharacter(Player) -- this will setup a new character if they reset or die
end)
end)
--[[ -- don't have to disconnect the connection to the player as they should be disconnected auto when player is destroyed on exit of the game
Players.PlayerRemoving:Connect(function(Player)
if Connections[Player] then
Connections[Player]:Disconnect()
Connections[Player] = nil
end
end)
--]]
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local GameDataModule = require(game.ReplicatedStorage.Modules.GameDataModule)
local RankDataModule = require(game.ReplicatedStorage.Modules.RankDataModule)
local OverheadTemplate = script.UserInformation
local Connections = {}
local function OnCharacterAdded(Character)
Players.PlayerAdded:Connect(function(Player)
Connections[Player] = Player.CharacterAdded:Connect(function(Character)
local Character = Player.Character or Player.CharacterAdded:Wait()
local NewOverhead = OverheadTemplate:Clone()
local PlayerIsInGroup = Player:IsInGroup(GameDataModule.GroupID)
if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, GameDataModule.Gamepass_Premium) then
NewOverhead.Main.Tags.Premium.Visible = true
NewOverhead.Main.Tags.Visible = true
end
if PlayerIsInGroup then
NewOverhead.Main.PlayerRank.Rank.Text = Player:GetRoleInGroup(GameDataModule.GroupID)
else
NewOverhead.Main.PlayerRank.Rank.Text = "Customer"
end
Character:WaitForChild("Humanoid").DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
NewOverhead.Parent = Character:WaitForChild("Head")
end)
end)
end
@Nyonic, @doggy00 thank you guys for helping me but after trying to test out the both of your guys’ script’s I wasn’t able to get them to work. I even wrote up the most basic script for this and moved the Billboard GUI in ReplicatedStorage to see if that changed anything and it didn’t.
Script:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
Players.PlayerAdded:Connect(function(Player)
local Character = Player.Character or Player.CharacterAdded:Wait()
local Head = Character:WaitForChild("Head")
local Humanoid = Character:WaitForChild("Humanoid")
local GameDataModule = require(ReplicatedStorage.Modules.GameDataModule)
local NewUserInformation = ReplicatedStorage.UserInformation
local PlayerIsInGroup = Player:IsInGroup(GameDataModule.GroupID)
if PlayerIsInGroup then
NewUserInformation.Main.PlayerRank.Rank.Text = Player:GetRoleInGroup(GameDataModule.GroupID)
else
NewUserInformation.Main.PlayerRank.Rank.Text = "Customer"
end
Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
NewUserInformation.Parent = Head
end)
also this is probably your issue here is what I suggest
first clone over the billboard then try to pull info to update it like rank and also role in group this way its there
I do this with values on the player or attributes using a -1 as the value for not loaded yet when it is loaded or change just update the ui
your requires on those modules is probably why its not loading the player or character function to even add the ui
you should use some prints in your script to determine where and when it is or is not loading
hmm idk, i updated my script and im still getting an error
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
Players.PlayerAdded:Connect(function(Player)
local Character = Player.Character or Player.CharacterAdded:Wait()
local Head = Character:WaitForChild("Head")
local Humanoid = Character:WaitForChild("Humanoid")
--local GameDataModule = require(ReplicatedStorage.Modules.GameDataModule)
local NewUserInformation = ReplicatedStorage.UserInformation
local PlayerIsInGroup = Player:IsInGroup(8723289)
if PlayerIsInGroup then
NewUserInformation.Main.PlayerRank.Rank.Text = Player:GetRoleInGroup(8723289)
else
NewUserInformation.Main.PlayerRank.Rank.Text = "Customer"
end
Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
NewUserInformation.Parent = Head
end)
so nothing shows up above my head but i have a tag inside of the bgui that shows when a player is afk and thats the error that shows that the bgui isnt in the players head
You might need to do a character setup function like above to make sure it catches the character and sets up right. You can even use characterappearance loaded to make sure its all the way loaded in
and use some prints in your code to make sure your script is even firing. this is one of the best debug tools, do something like this for prints
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
Players.PlayerAdded:Connect(function(Player)
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Head = Character:WaitForChild("Head")
--local GameDataModule = require(ReplicatedStorage.Modules.GameDataModule)
local NewUserInformation = ReplicatedStorage.UserInformation
Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
NewUserInformation.Parent = Head
print('ADDED TO HEAD')
-- do this after adding to head
local PlayerIsInGroup = Player:IsInGroup(8723289)
if PlayerIsInGroup then
NewUserInformation.Main.PlayerRank.Rank.Text = Player:GetRoleInGroup(8723289)
else
NewUserInformation.Main.PlayerRank.Rank.Text = "Customer"
end
print('SETUP INFO')
end)
but in your current script put all of this at the bottom and go a head and parent the gui to the player
local PlayerIsInGroup = Player:IsInGroup(8723289)
if PlayerIsInGroup then
NewUserInformation.Main.PlayerRank.Rank.Text = Player:GetRoleInGroup(8723289)
else
NewUserInformation.Main.PlayerRank.Rank.Text = "Customer"
end
Before I made this post the BGUI used to be in the HumanoidRootPart, but later on in developtment I relized it should be in the head, so switching this line (to see if it would work like how it used to)
to local Head = Character:WaitForChild("HumanoidRootPart") worked, but I want the BGUI to be in the Head and for some reason it just won’t parent.