Hi! I was testing my billboard and I just found a bug, when I respawn the billboard.text of the player it disappears! Why is this happening? how can i fix it? Someone could give me a hand, I would appreciate it very much.
Showing bug in the video:
I would like to make that, the new player who joins the game make his billboard.text as “Player” and if the reappears (doing respawn) his billboardText still the same text, until I want to change it for a different one in the future and this new text have to be saved.
I already have the datastorage created but I want the text to be saved if I modify it or if the player reappears in the game.
PD. Ignore the part tool it is only tests to learn xD
Server Script:
local DS = game:GetService("DataStoreService")
local Datastore = DS:GetDataStore("MyDatastore")
game.Players.PlayerAdded:Connect(function(player)
local Char = player.Character or player.CharacterAdded:Wait()
local BillboardGUI = Instance.new('BillboardGui')
BillboardGUI.Name = 'Billboard'
BillboardGUI.Size = UDim2.new(3, 0, 1, 0)
BillboardGUI.StudsOffset = Vector3.new(0, 2, 0) -- change the number 2 to make it go higher or lower
BillboardGUI.Parent = Char.Head
local TextLabel = Instance.new("TextLabel")
TextLabel.Size = UDim2.new(1,0,1,0)
TextLabel.Name = "TextLabel"
TextLabel.TextScaled = true
TextLabel.Parent = BillboardGUI
print("BillboardGUI Given to "..player.Name)
-- BillboardData
local Data
local success, errormessage = pcall(function()
Data = Datastore:GetAsync(player.UserId)
end)
if success then
print("Loaded "..player.Name)
if Data ~= nil then
print(player.Name.." has saved data")
TextLabel.Text = Data.Billboardtext
else -- If the Player is new
print(player.Name.." doesn't have saved data")
TextLabel.Text = "Player"
TextLabel.TextColor3 = Color3.fromRGB(255, 238, 245)
TextLabel.TextStrokeTransparency = 1 -- can be change (el contorno)
TextLabel.BackgroundTransparency = 1
end
else
warn(errormessage)
print("In the data is something wrong.")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local Data = {
BillboardText = player.Character.Head.Billboard.TextLabel.Text
}
local success, errormessage = pcall(function()
Datastore:SetAsync(player.UserId, Data)
end)
if success then
print("Saved "..player.Name)
else
print("Error saving "..player.Name)
end
end)
Because I want the billboardText to be saved in the player, since everyone will have roles, when changing the player’s role I want it to have a different text and that when leaving and rejoining the game it will continue to have the same text
local function createBillboard(char)
local BillboardGUI = Instance.new('BillboardGui')
BillboardGUI.Name = 'Billboard'
BillboardGUI.Size = UDim2.new(3, 0, 1, 0)
BillboardGUI.StudsOffset = Vector3.new(0, 2, 0) -- change the number 2 to make it go higher or lower
BillboardGUI.Parent = char.Head
local TextLabel = Instance.new("TextLabel")
TextLabel.Size = UDim2.new(1,0,1,0)
TextLabel.Name = "TextLabel"
TextLabel.TextScaled = true
TextLabel.Parent = BillboardGUI
end
---
game.Players.PlayerAdded:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()
createBillboard(character)
player.CharacterAdded:Connect(createBillboard)
-- rest of the func would go here
Create a variable that contains the rank, then when the character is added, set it to this rank. We’re going to have to rearrange our function for this though.
local function createBillboard(character, text)
local BillboardGUI = Instance.new('BillboardGui')
BillboardGUI.Name = 'Billboard'
BillboardGUI.Size = UDim2.new(3, 0, 1, 0)
BillboardGUI.StudsOffset = Vector3.new(0, 2, 0)
BillboardGUI.Parent = Char.Head
local TextLabel = Instance.new("TextLabel")
TextLabel.Size = UDim2.new(1,0,1,0)
TextLabel.Name = "TextLabel"
TextLabel.TextScaled = true
TextLabel.Parent = BillboardGUI
TextLabel.Text = "Player"
TextLabel.TextColor3 = Color3.fromRGB(255, 238, 245)
TextLabel.TextStrokeTransparency = 1
TextLabel.BackgroundTransparency = 1
end
game:GetService('Players').PlayerAdded:Connect(function(player)
local Data
local success, errormessage = pcall(function()
Data = Datastore:GetAsync(player.UserId)
end)
if success then
Data = Data or {BillboardText = 'Player'} -- Data variable is either the Data variable or the new table which contains the default data. Eliminates the need for the second if statement
player.CharacterAdded:Connect(function(character)
createBillboard(character, Data.BillboardText)
end)
end
end)