Leaderboard value making Gui Visible

1.What I’m trying to achieve is to have a GUI show for a player that reached the needed “Best Time Alive” value on the leaderboard.

  1. The issue: Lets say there’s 2 players in a server. 1 player has 600 “Best Time” while the other player has 250 “Best Time”. The way the game sees it: A Player has 600 “Best Time”. Making everyone else in the server have those skins unlocked (GUI’s visible) even if they haven’t reached the needed time.

  2. I haven’t found any solutions yet and searched as much as I can. Here’s the Server Script, located in StarterCharacterScripts:

local Stone = game.StarterGui["Tool Giver GUI"].Main.Stone
local Light = game.StarterGui["Tool Giver GUI"].Main.Light
local Dark = game.StarterGui["Tool Giver GUI"].Main.Dark
local Flame = game.StarterGui["Tool Giver GUI"].Main.Flame
local Electricity = game.StarterGui["Tool Giver GUI"].Main.Electricity
local players = game:GetService("Players")
local Player = players.LocalPlayer
local humanoid = script.Parent:WaitForChild("Humanoid")

local player = game.Players:GetPlayerFromCharacter(script.Parent)
local leaderstats = player:WaitForChild("leaderstats")
local aliveTime = leaderstats:WaitForChild("Time Alive")
local bestTime = leaderstats:WaitForChild("Best Time")

humanoid.Died:Connect(function()
	if aliveTime.Value > bestTime.Value then
		bestTime.Value = aliveTime.Value
	end

	aliveTime.Value = 0
end)

while wait(1) do
	if humanoid.Health == 0 then
		break
	end

	aliveTime.Value += 1
end

--This is where the "GUI visible when reached the needed value" takes place.

if bestTime.Value >= 250 then
	Stone.Visible = true
else Stone.Visible = false
end
------------------------------------------------
if bestTime.Value >= 380 then
	Light.Visible = true
else
	Light.Visible = false
end
------------------------------------------------
if bestTime.Value >= 500 then
	Dark.Visible = true
else
	Dark.Visible = false
end
------------------------------------------------
if bestTime.Value >= 680 then
	Flame.Visible = true
else
	Flame.Visible = false
end
------------------------------------------------
if bestTime.Value >= 1000 then
	Electricity.Visible = true
else
	Electricity.Visible = false
end

Idk if this one is needed but Here’s a server Script Called Stats located in ServerScriptService:

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("DataStore")

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

	local aliveTime = Instance.new("IntValue")
	aliveTime.Name = "Time Alive"
	aliveTime.Parent = leaderstats

	local bestTime = Instance.new("IntValue")
	bestTime.Name = "Best Time"
	bestTime.Parent = leaderstats

	local data

	local success, message = pcall(function()
		data = DataStore:GetAsync(plr.UserId .. "-Data")
	end)

	if success then
		if data then
			bestTime.Value = data
		end
	else
		warn(message)
		plr:Kick("Error while retrieving your data.")
	end
end)


game.Players.PlayerRemoving:Connect(function(plr)
	local data = plr.leaderstats["Best Time"].Value

	local success, message = pcall(function()
		DataStore:SetAsync(plr.UserId .. "-Data", data)
	end)

	if not success then
		warn(message)
	end
end)

I think the issues was that you’re using game.StarterGui and you’re using server script(Player.LocalPlayer will not work for server script) that’s mean when anyone got 600 Best Time everyone in the server will get the skin too so to fix this you need to change your server script to local script and change some variables at the top to:

local Players = game:GetService("Players")

local Player = Players.LocalPlayer

local Stone = Player.PlayerGui["Tool Giver GUI"].Main.Stone
local Light = Player.PlayerGui["Tool Giver GUI"].Main.Light
local Dark = Player.PlayerGui["Tool Giver GUI"].Main.Dark
local Flame = Player.PlayerGui["Tool Giver GUI"].Main.Flame
local Electricity = Player.PlayerGui["Tool Giver GUI"].Main.Electricity

Or else you don’t need to change your server script to local script just change some variables at the top to:

local Player = game.Players:GetPlayerFromCharacter(script.Parent)

local Stone = Player.PlayerGui["Tool Giver GUI"].Main.Stone
local Light = Player.PlayerGui["Tool Giver GUI"].Main.Light
local Dark = Player.PlayerGui["Tool Giver GUI"].Main.Dark
local Flame = Player.PlayerGui["Tool Giver GUI"].Main.Flame
local Electricity = Player.PlayerGui["Tool Giver GUI"].Main.Electricity

Hey this worked for the gui problem but now I’m not able to see other player’s “Time Alive” value updating. I can only see mine. Here’s the scripts again if it helps:

LocalScript located in StarterCharacterScripts:

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Stone = Player.PlayerGui["Tool Giver GUI"].Main.ScrollingFrame.Stone
local Light = Player.PlayerGui["Tool Giver GUI"].Main.ScrollingFrame.Light
local Dark = Player.PlayerGui["Tool Giver GUI"].Main.ScrollingFrame.Dark
local Flame = Player.PlayerGui["Tool Giver GUI"].Main.ScrollingFrame.Flame
local Electricity = Player.PlayerGui["Tool Giver GUI"].Main.ScrollingFrame.Electricity
local humanoid = script.Parent:WaitForChild("Humanoid")
local leaderstats = Player:WaitForChild("leaderstats")
local aliveTime = leaderstats:WaitForChild("Time Alive")
local bestTime = leaderstats:WaitForChild("Best Time")
--This is where the "GUI visible when reached the needed value" takes place.
if bestTime.Value >= 250 then
	Stone.Visible = true
else Stone.Visible = false
end
------------------------------------------------
if bestTime.Value >= 380 then
	Light.Visible = true
else
	Light.Visible = false
end
------------------------------------------------
if bestTime.Value >= 500 then
	Dark.Visible = true
else
	Dark.Visible = false
end
------------------------------------------------
if bestTime.Value >= 800 then
	Flame.Visible = true
else
	Flame.Visible = false
end
------------------------------------------------
if bestTime.Value >= 1000 then
	Electricity.Visible = true
else
	Electricity.Visible = false
end

humanoid.Died:Connect(function()
	if aliveTime.Value > bestTime.Value then
		bestTime.Value = aliveTime.Value
	end

	aliveTime.Value = 0
end)

while wait(1) do
	if humanoid.Health == 0 then
		break
	end

	aliveTime.Value += 1
end

ServerScript located in ServerScriptService:

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("DataStore")

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

	local aliveTime = Instance.new("IntValue")
	aliveTime.Name = "Time Alive"
	aliveTime.Parent = leaderstats

	local bestTime = Instance.new("IntValue")
	bestTime.Name = "Best Time"
	bestTime.Parent = leaderstats

	local data

	local success, message = pcall(function()
		data = DataStore:GetAsync(plr.UserId .. "-Data")
	end)

	if success then
		if data then
			bestTime.Value = data
		end
	else
		warn(message)
		plr:Kick("Error while retrieving your data.")
	end
end)


game.Players.PlayerRemoving:Connect(function(plr)
	local data = plr.leaderstats["Best Time"].Value

	local success, message = pcall(function()
		DataStore:SetAsync(plr.UserId .. "-Data", data)
	end)

	if not success then
		warn(message)
	end
end)

Look like your code need to be update in server script so can you change your script back to server script and use this?:

local Player = game.Players:GetPlayerFromCharacter(script.Parent)

local Stone = Player.PlayerGui["Tool Giver GUI"].Main.Stone
local Light = Player.PlayerGui["Tool Giver GUI"].Main.Light
local Dark = Player.PlayerGui["Tool Giver GUI"].Main.Dark
local Flame = Player.PlayerGui["Tool Giver GUI"].Main.Flame
local Electricity = Player.PlayerGui["Tool Giver GUI"].Main.Electricity
1 Like

This fixed it! thank you so much for helping!!!

1 Like

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