Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I make a script that adds to a value in the leaderboards when I hit the throttle on a car?

I have some basic ideas for instance :

if script.Parent.Throttle == 1 then value = value +1 end

if script.Parent.Throttle == 1 then value = value +1 end

But I don't know how to find the value as it's player specific...

I have never used data persistence so please dumb it down.

Thanks,

Llamakid15

1 answer

✓ Accepted answer

Sorry, I messed up an edit and lost my first bit here. If any admins are online, if you could revert this to the first version that would be fantastic.

local seat = script.Parent -- Change me to where the VehcileSeat is
local statName = "Points" -- The name of the stat you want to change

seat.Changed:connect(function(val) -- When a property changes
	if (val == "Throttle" and seat.Throttle == 1 and seat:FindFirstChild("SeatWeld")) then
		local sittingChar = seat.SeatWeld.Part1.Parent -- Who is sitting in the seat

		if (sittingChar and player.Players:FindFirstChild(sittingChar.Name)) then -- If they're a player, which they probably are. This is just a procaution
			game.Players[sittingChar.Name].leaderstats[statName] = game.Players[sittingChar.Name].leaderstats[statName] + 1 -- Add one to the given stat
		end
	end
end)

2 comments

0

Thankyou very much, Do I need to add a wait anywhere as I don't want it to hit 1 million as soon as a player hits the throttle...

0

That will only increase their points once they hit the throttle once (and again the next time they hit it). Would you like me to change it so that its always giving them points when they're hitting the throttle?

This discussion is preserved as it was. New answers, comments, and votes are closed.