Drive for money

So I’ve looked around for a bit but I can’t figure out how to make a script that when you’re in the seat and you’re moving your leaderboard cash goes up. I’ve seen some articles but not really sure how to write it. I was thinking something like a script for distance if and only if player is in the seat. If someone could help that would be great! Also I was thinking about using this for the inspare chassis idk if that matters. Thanks from John.

5 Likes

You can use this tutorial from DevHub to check if the player is seated. Simply add a loop that adds 1 to the player’s leaderstat for every second they’re sitting.

Edit: If you’re struggling, I can attempt to write most of it for you, just tell me. Good luck! :smile:

Edit 2: Hi future people! This is a place file that (should) work. @Strongjohnfgamer asked me to make it work with INSPARE, however, you should be able to use it with any seat.

aaaa.rbxl (78.2 KB)

9 Likes

This script should be ran off the server and not the client, doing so off the client doesnt update it so that the server see’s that the player actually has cash, Here is a Quick fix I did, it still goes in the StarterCharacterScripts instead of leaderboard though it uses data, feel free to change it.

Server Script:

local UserBody = script.Parent
local User = game.Players:GetPlayerFromCharacter(UserBody)
local UserHumanoid = UserBody:WaitForChild("Humanoid")
local Sitting = false
UserHumanoid.Seated:Connect(function(IsSeated, Seat)
if IsSeated then
if Seat then
Sitting = true
while true do
wait(1)
local UserHumanoidRootPart = UserBody:FindFirstChild("HumanoidRootPart")
if Sitting == true and UserHumanoidRootPart then
local Speed = UserHumanoidRootPart.AssemblyLinearVelocity.Magnitude
User.Data.Currency.Value = User.Data.Currency.Value + math.floor(Speed/1.5)
end
end
end
else
Sitting = false
end
end)
2 Likes

If I was to run this off the server script if one person got out would it stop giving money to the other players who are still driving?

No it will continue to work normally on other player’s instance because the script is in StarterCharacterScripts as @LilSk8rBoi said

that means that the script will be duplicated in the character of each player so no it will not stop giving other players money