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

Is it possible to make a drive for money script by using the variable speed from another script?

I am making a driving game, and I am new to coding, I am trying to implement a drive for money system, but can't find any tutorials to give me the resources to make the script, I already have a reward system in place, and all I need is a way of verifying if someone is driving, to give them money,I need a way of using variables across scripts, so I can verify that the car is moving

amount = 5 
timedelay = 5 
currencyname = "Cash" 

if speed >0 then
	wait(timedelay)
	for i,v in pairs(game.Players:GetPlayers()) do
		if v:FindFirstChild("leaderstats") and v then
			v.leaderstats[currencyname].Value = v.leaderstats[currencyname].Value + amount
		end
	end
end

the if speed > 0 then is the problem, since I am not able to share the 'speed' variable between scripts, the reward system does not function!

I put the script that measures the speed into the seat of the vehicle,

local seat = script.Parent
local speed = seat.Velocity.magnitude
print(speed)

I used the print to test out the script, so I could find the issue, but I haven't found out what to do. All help accepted and improvements for the script in general accepted too! phoniexgaming(I call myself PhonieZGaminZ now!)

1 answer

✓ Accepted answer

Get the speed of the players vehicle not from within in the seat but from the leaderstats script. I recommend parenting vehicles to a folder called vehicles, for i,v within the vehicles folder, and then get the driver of the seat and reward to them.

3 comments

0

thanks

0

but how do I get the speed of the players vehicle from the leaderstats script?

0

car.VehicleSeat.Velocity.Magnitude

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