Overhead GUI help!

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

Could you send your OverheadGUI along with your regular script that sets the leaderstats to me?

You can just right click the OverheadGui and press save to file, and you can just paste the script and send it so I can fix it much quicker.

1 Like

I tried to do it but I already deleted everything

This was the tutorial i watched though

But for some reason it didnt work and gave me error in this script

game.Players.PlayerAdded:Connect(function(plr)
     local 1Stats = Instance.new("Folder", plr)
     1Stats.Name = "leaderstats"

     local cash = Instance.new("IntValue", 1Stats)
     cash.Name = "Cash"
end)

The error was something with 1stats

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

Okay, I’ll tell you how to do it in a few steps.

  1. Switch out your leaderstats script with this:
--//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)
  1. 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)
    image

  2. You’re finished, if it doesn’t work, please tell me if there are any errors and what they are if there are any.

1 Like

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)

Are you sure there isn’t any other scripts that are creating leaderstats in your game? It worked for me when I tried it.

1 Like

Yeah I am sure. The leaderboard on top right works but the GUI is at Souls: 0 and the 0 does not change for some reason.

Also I wanted to ask does the leaderboard script you gave save?

Could you show me all the scripts in ServerScriptService?

1 Like

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.

Oh wait, nevermind, I made a mistake.

Fixed code:

--//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)
2 Likes

I’ll make a version that saves in a minute.

1 Like

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?

1 Like

You should just use this one I made.

Switch out that fixed script with this:

--//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.

1 Like

Oh well it seems to be broken it doesnt show the GUI at all now. i guess i will keep my save script then since its working with no issues

1 Like

Hm that’s really weird, I didn’t change anything related to the gui, I only just added saving. At least your problem is fixed though.

2 Likes

Yep thanks it is working perfectly now.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.