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

Why are Billboardguis being destoryed when :LoadCharacter() is over?

The title really explains the issue, here is my scripts:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PlayerAddedEvent = game.ReplicatedStorage.PlayerAddedEvent
local Playername = nil
local Counter = 0
game.Players.PlayerAdded:Connect(function(plr)
		local GuiClone = Instance.new("BillboardGui")
		NameLabel = Instance.new("TextLabel",GuiClone)
		GuiClone.Size = UDim2.new(3.5, 0,2, 0)
		GuiClone.ResetOnSpawn = false
		playerplr = plr
		GuiClone.ExtentsOffset = Vector3.new(0,3,0)
		NameLabel.Position = UDim2.new(0,0,0.5,0)
		NameLabel.Size = UDim2.new(1,0,0.5,0)
		NameLabel.Font = Enum.Font.GothamSemibold
		NameLabel.BackgroundTransparency = 1
		NameLabel.TextScaled = true
		NameLabel.Text = plr.Name
		plr.Team = game.Teams.Joining
		plr.RespawnLocation = game.Workspace.TeamSpawns.JoiningSpawn 
	plr.CharacterAdded:Wait()
	Char = plr.Character
	print(Char)
	local hum = Char:WaitForChild("Humanoid")
	GuiClone.Parent = Char:WaitForChild("Head")
	GuiClone.Adornee = GuiClone.Parent
	if hum then
	hum.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff
	hum.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
	game.ReplicatedStorage.PlayerAddedEvent:FireClient(plr)
		end
end)
game.ReplicatedStorage.TeamChanger.OnServerInvoke = function(player, PickedTeam, TeamSpawn, Color)
	game.Players.CharacterAutoLoads = false
	playerplr:LoadCharacter()
	NameLabel.TextColor3 = Color
	player.Team = PickedTeam
	player.RespawnLocation = TeamSpawn
end

I'd like to note that the Remote Event just goes to a local script to grab properties that a player has picked, and Teamchanger brings properties back. This is a ServerScript. The problem is when the LoadCharacter() plays, the Billboardgui gets destroyed it looks like. Any help would be great, thanks!

7 comments

0

So the billboardgui is inside of a dummy and when your player loads in, the billboardgui gets destroyed?

0

Also those print("hi") things was just for testing to see what was wrong with the script earlier, I just forgot to delete them.

0

No, that dummy one was also used before I redid the script, just didn't delete it, woops. When a player is added a gui appears above them with their name. And when they click a team changer, it goes to the local script to get the team they want to be on, and comes back with the team, spawn, and the color the text should change to. When :LoadCharacter plays, the Billboardgui gets destroyed.

0

When LoadCharacter is fired, it gets a fresh copy of the character, so you'll need to put the gui back into the character when they load.

0

It still goes missing. I may have misunderstood you. After the LoadCharacter ran I just did GuiClone.Parent = Char:WaitForChild("Head") GuiClone.Adornee = GuiClone.Parent right after it. Is that what you meant?

0

I actually have a script that does something like this, so I'll see if I can modify it to work with your system. I'll give it to you in an answer in a few minutes.

0

Alright, thank you!

1 answer

✓ Accepted answer

So it might look very different, but all I added was support for the player respawning. Also the gui gets made outside of the player added so that it isn't remade everytime a player joins, it gets made once, and everytime a player respawns, the gui gets cloned into the character.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PlayerAddedEvent = game.ReplicatedStorage.PlayerAddedEvent
local Playername = nil
local Counter = 0

game.Players.CharacterAutoLoads = false --if you dont want them to load, then this should be first.

local GuiClone = Instance.new("BillboardGui")
local NameLabel = Instance.new("TextLabel",GuiClone)
GuiClone.Size = UDim2.new(3.5, 0,2, 0)
GuiClone.ResetOnSpawn = false
GuiClone.ExtentsOffset = Vector3.new(0,3,0)
NameLabel.Position = UDim2.new(0,0,0.5,0)
NameLabel.Size = UDim2.new(1,0,0.5,0)
NameLabel.Font = Enum.Font.GothamSemibold
NameLabel.BackgroundTransparency = 1
NameLabel.TextScaled = true

local function onPlayerRespawned(character)
	local gui = GuiClone:Clone()
	gui.Parent = character.Head
	gui.TextLabel.Text = character.Name
	gui.Adornee = character.Head
	character.Humanoid.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff
	character.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
end

function onPlayerEntered(Player)
	Player.CharacterAdded:Connect(onPlayerRespawned)
	Player.CharacterAppearanceLoaded:Wait()
	Player.Team = game.Teams.Joining
	Player.RespawnLocation = game.Workspace.TeamSpawns.JoiningSpawn
	game.ReplicatedStorage.PlayerAddedEvent:FireClient(Player)
end 

game.Players.PlayerAdded:Connect(onPlayerEntered)

game.ReplicatedStorage.TeamChanger.OnServerInvoke = function(player, PickedTeam, TeamSpawn, Color)
    player:LoadCharacter()
	NameLabel.TextColor3 = Color
	player.Team = PickedTeam
	player.RespawnLocation = TeamSpawn
end

If this works, then mark it as the accepted answer, if not, then let me know what goes wrong.

1 comment

0

Yes it worked! I did move the AutoLoad because the character won't load right when you join. Thank you!

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