Hi, I have created a BillboardGUI and put it in the player’s head (all from server side) and I would like to save it in datastore, I want it to be saved.
Is it okay what I have done?
I’m a bit worried, as I would like each “Role” (different names) to have their own custom BillboardGUI on their head.
For example, if it is Role “player” then the billboardgui will say “New player” things like that.
I would also like to know how to save in datastore, should I follow the same steps as with the stringValue? I would very much appreciate a hand, thank you!
Server script:
local DataStoreService = game:GetService('DataStoreService')
local RanksDataStores = DataStoreService:GetDataStore('RanksDataStores')
local BillboardDataStores = DataStoreService:GetDataStore('BillboardDataStores')
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new('Folder', player)
leaderstats.Name = 'leaderstats'
local Ranks = Instance.new('StringValue', leaderstats)
Ranks.Name = 'Roles'
-- NEW! billboard here.
local BillboardGUI = Instance.new('BillboardGui', player.Character.Head)
BillboardGUI.Name = 'Billboard'
BillboardGUI.Size = UDim2.new(3, 0, 1, 0)
local TextLabel = Instance.new("TextLabel", BillboardGUI)
TextLabel.Text = "New Player!"
TextLabel.Size = UDim2.new(1,0,1,0)
print("BillboardGUI Given to "..player.Name)
-- BillboardData
local BillboardData
local bsuccess, berrormessage = pcall(function()
BillboardData = BillboardDataStores:GetAsync('BillboardGUI_'..player.UserId)
end)
if BillboardData and bsuccess then
player.Character.Head.BillboardGUI.TextLabel.Text = "New Text"
print("Billboard Data saved!")
else
warn(berrormessage)
print("In the billboard data is something wrong.")
end
local RanksData
local success, errormessage = pcall(function()
RanksData = RanksDataStores:GetAsync('Ranks_'..player.UserId)
end)
if RanksData and success then
player.leaderstats.Roles.Value = RanksData
print("Data has been saved!")
else
warn(errormessage)
print("There is something wrong.")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local Ranks = player.leaderstats.Roles
local success, errormessage = pcall(function()
RanksDataStores:SetAsync("Ranks_" .. player.UserId, Ranks.Value)
end)
local Billboard = player.Character.Head.BillboardGUI.TextLabel
local bsuccess, berrormessage = pcall(function()
BillboardDataStores:SetAsync("Billboard_".. player.UserId, Billboard.Text)
end)
end)
By the way because it is in the characters head it will not show on it you need to set its adornee to the characters head aswell lol (Just so you know)
I’ve already fixed that bug, but I still don’t know how to make the billboardgui text save to datastores…
Updated script
local DataStoreService = game:GetService('DataStoreService')
local RanksDataStores = DataStoreService:GetDataStore('RanksDataStores')
local BillboardDataStores = DataStoreService:GetDataStore('BillboardDataStores')
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new('Folder', player)
leaderstats.Name = 'leaderstats'
local Ranks = Instance.new('StringValue', leaderstats)
Ranks.Name = 'Roles'
-- NEW! billboard here.
local Character = player.Character or player.CharacterAdded:Wait()
local BillboardGUI = Instance.new('BillboardGui', Character.Head)
BillboardGUI.Name = 'Billboard'
BillboardGUI.Size = UDim2.new(3, 0, 1, 0)
local TextLabel = Instance.new("TextLabel", BillboardGUI)
TextLabel.Text = "New Player!"
TextLabel.Size = UDim2.new(1,0,1,0)
print("BillboardGUI Given to "..player.Name)
-- BillboardData
local BillboardData
local bsuccess, berrormessage = pcall(function()
BillboardData = BillboardDataStores:GetAsync('BillboardGUI_'..player.UserId)
end)
if BillboardData and bsuccess then
player.Character.Head.BillboardGUI.TextLabel.Text = BillboardData -- if doesnt work then try tostring(RanksData)
print("Billboard Data saved!")
else
warn(berrormessage)
print("In the billboard data is something wrong.")
end
local RanksData
local success, errormessage = pcall(function()
RanksData = RanksDataStores:GetAsync('Ranks_'..player.UserId)
end)
if RanksData and success then
player.leaderstats.Roles.Value = RanksData
print("Data has been saved!")
else
warn(errormessage)
print("There is something wrong.")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local Ranks = player.leaderstats.Roles
local success, errormessage = pcall(function()
RanksDataStores:SetAsync("Ranks_" .. player.UserId, Ranks.Value)
end)
local Character = player.Character or player.CharacterAdded:Wait()
local bsuccess, berrormessage = pcall(function()
BillboardDataStores:SetAsync("Billboard_".. player.UserId, Character.Head)
end)
end)
You still aren’t saving this correctly. You’re trying to save the Character.Head instance in that script. I believe you should try finding the BillboardGui and then the label object.
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 leaderstats = Instance.new('Folder')
leaderstats.Name = 'leaderstats'
leaderstats.Parent = player
local Ranks = Instance.new('StringValue')
Ranks.Name = 'Roles'
Ranks.Parent = leaderstats
-- NEW! billboard here.
local BillboardGUI = Instance.new('BillboardGui')
BillboardGUI.Name = 'Billboard'
BillboardGUI.Size = UDim2.new(3, 0, 1, 0)
BillboardGUI.Parent = Char.Head
local TextLabel = Instance.new("TextLabel")
TextLabel.Size = UDim2.new(1,0,1,0)
TextLabel.Name = "TextLabel"
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
Ranks.Value = Data.Ranks
else -- If the Player is new
print(player.Name.." doesn't have saved data")
TextLabel.Text = "NewText" -- Or put what you want if the player is new
Ranks.Value = "" -- Or put what you want if the player is new
end
else
warn(errormessage)
print("In the data is something wrong.")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local Data = {
Rank = player.leaderstats.Roles.Value;
BillboardText = player.Character.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)
Yes, that exactly! thanks a lot! By the way, how can I make the billboard a little higher? and how can i do to keep its size (text) along with the billboard when i do zoom-in and zoom-out in the game??
You can change the BillboardGui’s StudsOffset value to make it higher. You can turn on the TextLabel’s TextScaled value to make the text scale with the gui.
I have added this to the 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 leaderstats = Instance.new('Folder')
leaderstats.Name = 'leaderstats'
leaderstats.Parent = player
local Ranks = Instance.new('StringValue')
Ranks.Name = 'Roles'
Ranks.Parent = leaderstats
-- NEW! billboard here.
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
Ranks.Value = Data.Ranks
else -- If the Player is new
print(player.Name.." doesn't have saved data")
TextLabel.Text = "NewText" -- Or put what you want if the player is new
Ranks.Value = "" -- Or put what you want if the player is new
end
else
warn(errormessage)
print("In the data is something wrong.")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local Data = {
Rank = player.leaderstats.Roles.Value;
BillboardText = player.Character.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)