Hello. I am trying to make a script that gives a player money while they are driving! This is what I have tried
local cashadd = 335
local distadd = 33
local owner = script.Parent.Parent.Parent.Parent.Parent.Name
local user = game.Players:findFirstChild(owner)
local data = user:findFirstChild("Playerdata")
local stats = user:findFirstChild("leaderstats")
---------- Vector Calculation ----------
function GetSpeed(part)
pPos = part.Position;
wait(1)
oPos = part.Position;
pRspeed = {x=0,y=0,z=0}
oRspeed = {x=0,y=0,z=0}
pRspeed.x = math.floor(pPos.x);
pRspeed.y = math.floor(pPos.y);
pRspeed.z = math.floor(pPos.z);
oRspeed.x = math.floor(oPos.x);
oRspeed.y = math.floor(oPos.y);
oRspeed.z = math.floor(oPos.z);
IForce = {x=0,y=0,z=0}
IForce.x = pRspeed.x + -oRspeed.x
IForce.y = pRspeed.y + -oRspeed.y
IForce.z = pRspeed.z + -oRspeed.z
if(IForce.x < 0) then
IForce.x = -IForce.x;
end
if(IForce.y < 0)then
IForce.y = -IForce.y;
end
if(IForce.z < 0)then
IForce.z = -IForce.z;
end
speed = math.max(IForce.x,IForce.y,IForce.z);
return
speed;
end
---------- Cash Bonus ----------
while true do
wait()
if script.Parent.Throttle ~= 0 and script.Parent.Steer == 0 then
Speed = GetSpeed(script.Parent);
if speed > 20 then
local cash = data:findFirstChild("Money")
cash.Value = cash.Value + cashadd
local dist = stats:findFirstChild("Miles")
dist.Value = dist.Value + distadd
end
end
end
I'm putting this in the vehicle's driver seat
edit: there is no output error

4 comments
cash not upgrading nor the miles
I edited my answer see that
?
Did you understand what I suggested?