Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 10 years ago

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

Log in to vote
1
Answered by 10 years ago

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)
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... llamakid15 5 — 10y
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? DaMrNelson 130 — 10y
Ad

Answer this question