So I already got a leaderboard and want to make my overhead gui based on the already existing leaderboard stat without creating new stat value or whatever I have tried many times but for some reason the gui wouldnt show itself
The stats is just kills, does anyone have a working script for this? it can just be white text with my stat value i dont need the gui to look really good or whatever.
I would appreciate the help I have been trying alot but it keeps failing
Im not really sure though if the scripts that I used take the stat from my leaderboard maybe instead it creates a new stat so which could be messing up things…
its hard for me to understand since i am a beginner
--//Services
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
--//Variables
local OverheadGui = ServerStorage.OverheadGui
--//Functions
Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Parent = leaderstats
cash.Changed:Connect(function(newValue)
local character = player.Character
local overheadGui = character and character:FindFirstChild("OverheadGui")
if overheadGui then
overheadGui.TextLabel.Text = "Cash: $".. newValue
end
end)
player.CharacterAdded:Connect(function(character)
local newOverheadGui = OverheadGui:Clone()
newOverheadGui.TextLabel.Text = "Cash: $".. cash.Value
newOverheadGui.Parent = character:WaitForChild("Head")
end)
end)
Make a new billboard gui which is gonna be your money display in ServerStorage, here’s the layout:
(names must remain the same but properties can be whatever you want)
You’re finished, if it doesn’t work, please tell me if there are any errors and what they are if there are any.
The problem I am having now is that the value on my leaderboard changes but my GUI is at 0
This is the script I modified btw
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
--//Variables
local OverheadGui = ServerStorage.OverheadGui
--//Functions
Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Souls = Instance.new("IntValue")
Souls.Name = "Souls"
Souls.Parent = leaderstats
Souls.Changed:Connect(function(newValue)
local character = player.Character
local overheadGui = character and character:FindFirstChild("OverheadGui")
if overheadGui then
overheadGui.TextLabel.Text = "Souls: ".. newValue
end
end)
player.CharacterAdded:Connect(function(character)
local newOverheadGui = OverheadGui:Clone()
newOverheadGui.TextLabel.Text = "Souls: ".. Souls.Value
newOverheadGui.Parent = character:WaitForChild("Head")
end)
end)
I was thinking it could be the modified version not working? because I changed something in it?? all I did was change all cash related things to souls.
--//Services
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
--//Variables
local OverheadGui = ServerStorage.OverheadGui
--//Functions
Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Souls = Instance.new("IntValue")
Souls.Name = "Souls"
Souls.Parent = leaderstats
Souls.Changed:Connect(function(newValue)
local character = player.Character
local head = character and character:FindFirstChild("Head")
local overheadGui = head and head:FindFirstChild("OverheadGui")
if overheadGui then
overheadGui.TextLabel.Text = "Souls: ".. newValue
end
end)
player.CharacterAdded:Connect(function(character)
local newOverheadGui = OverheadGui:Clone()
newOverheadGui.TextLabel.Text = "Souls: ".. Souls.Value
newOverheadGui.Parent = character:WaitForChild("Head")
end)
end)
Thank you so much it works now! Also I have a save leaderboard script and its working with your script should I keep it or use your version that you made?
--//Services
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local ServerStorage = game:GetService("ServerStorage")
--//Variables
local PlayerData = DataStoreService:GetDataStore("PlayerDataStore")
local OverheadGui = ServerStorage.OverheadGui
--//Functions
local function SaveData(player, data)
local success, errorMessage = pcall(PlayerData.SetAsync, PlayerData, player.UserId, data)
if not success then
warn(errorMessage)
end
end
local function OnPlayerRemoving(player)
SaveData(player, {
Souls = player.leaderstats.Souls.Value
})
end
Players.PlayerAdded:Connect(function(player)
local playerData = PlayerData:GetAsync(player.UserId) or {
Souls = 0
}
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Souls = Instance.new("IntValue")
Souls.Name = "Souls"
Souls.Value = playerData.Souls
Souls.Parent = leaderstats
Souls.Changed:Connect(function(newValue)
local character = player.Character
local head = character and character:FindFirstChild("Head")
local overheadGui = head and head:FindFirstChild("OverheadGui")
if overheadGui then
overheadGui.TextLabel.Text = "Souls: ".. newValue
end
end)
player.CharacterAdded:Connect(function(character)
local newOverheadGui = OverheadGui:Clone()
newOverheadGui.TextLabel.Text = "Souls: ".. Souls.Value
newOverheadGui.Parent = character:WaitForChild("Head")
end)
end)
Players.PlayerRemoving:Connect(OnPlayerRemoving)
game:BindToClose(function()
for i, player in ipairs(Players:GetPlayers()) do
task.spawn(OnPlayerRemoving, player)
end
end)
This will save, also please set my reply as the solution if it works.