Basically im trying to make it so when your data fully loads from datastoreservice then a billboardgui will appear over your head. But it’s not working, now it doesn’t even load data. How would I fix this?
code:
local success, errormessage = pcall(function()
cashdata = myDataStore:GetAsync(player.userId.."-cash")
agedata = myDataStore:GetAsync(player.userId.."-age")
end)
if success then
cash.Value = cashdata
age.Value = agedata
clonedgui.TextLabel.Text = "Age: "..player.Stats.Age.Value
clonedgui.Parent = game.Workspace:WaitForChild(player).Head
else
warn("Error retrieving data"..errormessage)
end
end)
Full code:
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
local age = DataStoreService:GetAge()
local gui = game:GetService("ReplicatedStorage").GUIS.AgeB
local clonedgui = gui:Clone()
game.Players.PlayerAdded:Connect(function(player)
local Stats1 = Instance.new("Folder")
Stats1.Name = "Stats"
Stats1.Parent = player
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Parent = Stats1
local age = Instance.new("IntValue")
age.Name = "Age"
age.Parent = Stats1
local warns = Instance.new("IntValue")
warns.Name = "Warnings"
warns.Parent = Stats1
local cashdata
local agedata
warns.Changed:Connect(function()
if warns.Value == 3 then
player:Kick("3 warnings")
end
end)
local success, errormessage = pcall(function()
cashdata = myDataStore:GetAsync(player.userId.."-cash")
agedata = myDataStore:GetAsync(player.userId.."-age")
end)
if success then
cash.Value = cashdata
age.Value = agedata
clonedgui.TextLabel.Text = "Age: "..player.Stats.Age.Value
clonedgui.Parent = game.Workspace:WaitForChild(player).Head
else
warn("Error retrieving data"..errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserId.."-cash",player.Stats.Cash.Value)
myDataStore:SetAsync(player.UserId.."-age",player.Stats.Age.Value)
end)
if success then
print("Player Data has been successfully saved")
else
warn("Error saving Player Data"..errormessage)
end
end)