Need a little assistance with a script!

Sorry for reposting this but I’m trying to fix a timer in my obby so people can have fun competing. Before you ask, it is not round based! The rest of the scripts for the timer and the leaderboard work perfectly fine but I just wanted the script to do the opposite of what the youtuber put at the top! I want to make it so that even if the player dies from start to finish they can have a time on the leaderboard still. Like I said, it works flawlessly but I just want to make it so that even if the player dies from when they touch the StartTimer and the EndTimer, they can still have a spot on the leaderboard! Only things I changed in this script is the Datastore thingy that says “leaderboardData4” and the Anti-cheat timer! Pay attention to the words at the top of the script please!


--[[
	@author TwinPlayzDev_YT
	@since 6/1/2021
	This script will apply the leaderboard time, and check if a player has finished or completed the obby.
	Only saves time when they fully complete course without dieing.
--]]

	-- [ SERVICES ] --

	local DataStoreService = game:GetService("DataStoreService")

	-- [ LOCALS ] --

	local DataVer = "[DataTimer]" -- Data Store Name
	local Store = DataStoreService:GetOrderedDataStore("LeaderBoardData4")

	-- [ 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.UserId)

		if oldData then
			oldData = oldData / 1000
		else
			oldData = 1000
		end

		---- ANTI CHEAT (needs fixing)
		if num < oldData then
			if num <= 900.00 then
				plr:Kick("No cheating bucko!")
			else
				num = num * 1000
				Store:SetAsync(plr.Name, num)
			end
		end

	end)
1 Like

One fix could be to check when the player dies and then fire the ApplyTime remote event.

This script is in a LocalScript parented under StarterPlayerScripts.
At the bottom you’d need to put the time in.

You might wanna change a couple things in the server script because this is really easy for an exploiter to submit a fake time.

local plr = game.Players.LocalPlayer

plr.CharacterAdded:Wait()
task.wait()

local char = plr.Character
local hum = char:FindFirstChildWhichIsA("Humanoid")

plr.CharacterAdded:Connect(function()
	char = plr.Character
	hum = char:FindFirstChildWhichIsA("Humanoid")
end)

hum.Died:Connect(function()
	game.ReplicatedStorage.ApplyTime:FireServer(--[[the time]])
end)
1 Like

Yo I’m a beginner scripter and I just wanted to know if I could add that into my local script that I already have here for my timerGUI or do I need to make a separate script somewhere in the workspace?:

--[[
	This script handles the touch/stop plates for timer leaderboard.
--]]

-- [ SERVICES ] --

local RunService = game:GetService("RunService")

-- [ LOCALS ] --

local par=script.Parent

local timer=par:WaitForChild'Timer'
local timerlabel=timer:WaitForChild'Time'

local SetTime = tick()

local RationalDigits = 3 -- How many numbers is shown.

local timer_active=false
local timer_time=0

local prev

-- [ FUNCTIONS ] --

function connectplrtouch(pt,func)
	pt.Touched:Connect(function(t)
		local c=game.Players.LocalPlayer.Character
		if c and t:IsDescendantOf(c) then
			func()
		end
	end)
end

for _,d in pairs(workspace:GetDescendants()) do
	
	if d.Name=='TimerStart' then
		local name=(d:FindFirstChild'Title' and d.Title:IsA'StringValue' and d.Title.Value) or ''
		connectplrtouch(d,function()
			par.Enabled=true
			if prev~=d then
				SetTime = tick()
				prev=d
			end
			--timerlabel.Visible = true
			--timer.Visible = true
			timerlabel.TextColor3=Color3.new(1, 1, 1)
			SetTime = tick()
			timer_active=true
		end)
	end
	
	if d.Name=='TimerEnd' then
		connectplrtouch(d,function()
			timerlabel.TextColor3=Color3.new(0.172549, 1, 0.027451) -- Finish color
			if timer_active == true then
				game.ReplicatedStorage.ApplyTime:FireServer(timerlabel.Text)
			end
			timer_active=false
		end)
	end
	
end

local Accuracy = 10^RationalDigits

function TimerFunc()
	if timer_active then

		local Div1 = math.abs(tick() - SetTime)
		local CalculatedIncrement = math.round(Div1*Accuracy)/Accuracy
		local Addons={}
		for t=1,RationalDigits do
			local i = t-1
			local integer,predecimal = math.modf(CalculatedIncrement*(10^i))
			local decimal = predecimal/(10^i)
			if decimal == 0 then
				Addons[t] = "0"
			end

		end
		local NewText = tostring(CalculatedIncrement)
		for i,v in pairs(Addons) do
			NewText = NewText..v
		end
		timerlabel.Text=NewText	

	end
end

while true do
	wait(.025)
	TimerFunc()
end

I’m assuming that’s in StarterGui. The script mentioned above will not run in StarterGui because when you die things in StarterGui (or any ui in it with RespawnOnSpawn enabled) get reset.

1 Like

Oh, nah resetonspawn is disabled for the timerGUI. When they walk through the green timer starter it keeps going until they reach the red one which is at stage 100

Then you should be able to do that.

1 Like

I added the local script to starterplayerscripts BUT I’m confused at this line. What do I put in the parenthesis? what time?

	game.ReplicatedStorage.ApplyTime:FireServer**(--[[the time]])**

Looks like the timerlabel.Text … that will fire a remote named ApplyTime.
But there needs to also be a script to pick that up and actually add it to the leaderboard.

game.ReplicatedStorage.ApplyTime.OnServerEvent:connect(function(player,time)

You can always make a scrolling leadboard with many slots open. so even the smallest time has a shot at the leaderboard.

1 Like

You don’t need to mention Player, it automatically does it.
For the code we’ll need a screenshot of your UI with the text label that shows the time.

1 Like

Yes, you’re right … the 1st value is always the player … may as well put in place.
That is the OnServerEvent call …

1 Like

Like take a screenshot ingame or in studio?

image

These?

The one at the top is what I meant.
The updated code should be

	game.ReplicatedStorage.ApplyTime:FireServer(game.Players.LocalPlayer.PlayerGui.ObbyTimer.Timer.Time.Text)

Could be better but that works.

1 Like

So, if I’m correct this is the correct local script in starterplayerscripts?

local plr = game.Players.LocalPlayer

plr.CharacterAdded:Wait()
task.wait()

local char = plr.Character
local hum = char:FindFirstChildWhichIsA("Humanoid")

plr.CharacterAdded:Connect(function()
	char = plr.Character
	hum = char:FindFirstChildWhichIsA("Humanoid")
end)

hum.Died:Connect(function()
	game.ReplicatedStorage.ApplyTime:FireServer(game.Players.LocalPlayer.PlayerGui.ObbyTimer.Timer.Time.Text)
end)

Yeah, looks like it should work.

1 Like

Alright mane Ima test it! Lemme go on and give you the solution though and preciate you for the help​:sunglasses: :+1:t4:

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