Need help with a script that only displays a player's time on the leaderboard if they don't die the entire time

Yo, I’m a beginner scripter and I just wanted to ask y’all on here how I could change this script to where it displays a person’s time on the leaderboard even if they’ve died. Right now, it only makes the time show on the leaderboard only if they didn’t die from stage 1-100! I’m also making another post right after this one about the other script that displays the players’ names and time trials!

-- [ SERVICES ] --

local DataStoreService = game:GetService("DataStoreService")

-- [ LOCALS ] --

local DataVer = "DataTimer" -- Data Store Name
local Store = DataStoreService:GetOrderedDataStore(DataVer.."LeaderBoardData")

-- [ FUNCTIONS ] --

_G.ForceSet = function(plrName, newTime)
	local num = tonumber(newTime)

	num = num * 1000
	Store:SetAsync(plrName, num)
end

game.ReplicatedStorage.ApplyTime.OnServerEvent:Connect(function(plr, newTime) -- On Event
	
	local num = tonumber(newTime)
	local oldData = Store:GetAsync(plr.Name)
	
	if oldData then
		oldData = oldData / 1000
	else
		oldData = 1000
	end
	
	---- ANTI CHEAT (needs fixing)
	if num < oldData then
		if num <= 900.30 then
			plr:Kick("No cheating.")
		else
			num = num * 1000
			Store:SetAsync(plr.Name, num)
		end
	end
	
end)

As a general rule of thumb, try to explain what you have tried, what did not work, and why you think that is. We will be able to better help you then.

2 Likes

Oh I got you, I’ve tried publishing the game when I removed the script from serverscriptservice but that didn’t work! The youtuber I got the tutorial from didn’t show us viewers how to use the plugin called “Datastore Editor” in the comments but I won’t blame it on him! I just gotta get better :sunglasses: :+1:t4:

For now, I would just worry about the fundamentals and try to create a working timer for a single round instead of using datastores for this. The first approach you could use is to store each Player in a table, then update the table when a player dies. You can use events to do this by having the script that will update the table listen for an event when the player dies.

If that sounds overwhelming, just try your best, try to understand everything one step at a time, and ask good questions here that we can help you with to help you along. Programming is a skill you will learn in the time-span of years and not days. An entire college degree and 5 years of experience later I still have plenty to learn every day.

Best of luck and happy programming. Hope to see you on the forum helping us out one day.

1 Like

Preciate you gang! I don’t know you personally but I’m proud of you for gettin that degree and following your passion! Also, the timer works flawlessly along with the scripts, but the game isn’t round based! Here’s the game if you wanna check it out, regular obby but I want players to be able to compete with one another! Only thing wrong is I just wanna tweak the script above a bit so the timer can still show up on the board without the player resetting! I have no idea how to do that, but I’ll see if I can get in touch with the youtuber I got the tutorial from though. Have a good night! :sunglasses: :100:

1 Like

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