#can you help me with this script please
8 messages · Page 1 of 1 (latest)
i
local DataStoreService = game:GetService("DataStoreService")
local AgeDataStore = DataStoreService:GetDataStore("PlayerAges") -- Change "PlayerAges" to a unique name for your data store
local function updateAge(player)
while wait(1) do
if player.Parent == nil then
break -- Player left the game, stop updating their age
end
local leaderstats = player:FindFirstChild("leaderstats")
local ageValue = leaderstats and leaderstats:FindFirstChild("Age")
if ageValue then
ageValue.Value = ageValue.Value + 1
-- Save the updated age to the data store
local success, error = pcall(function()
AgeDataStore:SetAsync(tostring(player.UserId), ageValue.Value)
end)
if not success then
warn("Failed to save age for player " .. player.Name .. ": " .. error)
end
end
end
end
local function setupPlayer(player)
local leaderstats = player:FindFirstChild("leaderstats")
if not leaderstats then
leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
end
local ageValue = leaderstats:FindFirstChild("Age")
if not ageValue then
ageValue = Instance.new("IntValue")
ageValue.Name = "Age"
ageValue.Value = 0
ageValue.Parent = leaderstats
end
-- Load the saved age from the data store
local success, age = pcall(function()
return AgeDataStore:GetAsync(tostring(player.UserId))
end)
if success and age then
ageValue.Value = age
end
-- Start updating age
spawn(function()
updateAge(player)
end)
player.CharacterAdded:Connect(function(character)
character:WaitForChild("Humanoid")
local humanoid = character:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
-- Remove the BillboardGui when the player dies
local billboard = player:FindFirstChild("AgeBillboard")
if billboard then
billboard:Destroy()
end
end)
local billboard = Instance.new("BillboardGui")
billboard.Name = "AgeBillboard"
billboard.AlwaysOnTop = true
billboard.Size = UDim2.new(0, 100, 0, 50)
billboard.StudsOffset = Vector3.new(0, 3, 0) -- Adjust the height offset if needed
billboard.Adornee = humanoid.RootPart
billboard.Parent = game:GetService("Workspace")
local ageLabel = Instance.new("TextLabel")
ageLabel.Name = "AgeLabel"
ageLabel.Size = UDim2.new(1, 0, 1, 0)
ageLabel.Text = "Age: " .. ageValue.Value
ageLabel.TextColor3 = Color3.new(1, 1, 1)
ageLabel.BackgroundTransparency = 1
ageLabel.Font = Enum.Font.SourceSansBold
ageLabel.FontSize = Enum.FontSize.Size24
ageLabel.Parent = billboard
-- Update the age label
ageValue.Changed:Connect(function()
ageLabel.Text = "Age: " .. ageValue.Value
end)
end)
end
local function playerAdded(player)
-- Preserve existing leaderstats if they exist
local existingLeaderstats = player:FindFirstChild("leaderstats")
if not existingLeaderstats then
setupPlayer(player)
else
-- Existing leaderstats found, check if it has the "Age" value
local ageValue = existingLeaderstats:FindFirstChild("Age")
if ageValue then
setupPlayer(player)
else
-- Add "Age" value to existing leaderstats
ageValue = Instance.new("IntValue")
ageValue.Name = "Age"
ageValue.Value = 0
ageValue.Parent = existingLeaderstats
setupPlayer(player)
end
end
end
game.Players.PlayerAdded:Connect(playerAdded)
-- Loop through existing players when the script starts
for _, player in ipairs(game.Players:GetPlayers()) do
playerAdded(player)
end
i need help with the age billboard so that when it can disapper when i walk away from the player and it disappers just like the other players name
pls, use this text formating for code
** You are now Level 1! **