generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Car Nitro script doesn't work 100% of the time

Previous Thread :: Next Thread 
austint30 is not online. austint30
Joined: 20 Mar 2010
Total Posts: 1482
12 Nov 2015 08:50 PM
My nitro script, which is built for an ss3 chassis car, just doesn't work 100% of the time.

It would work 50/50 usually.

Also, there are other localscripts controlling the torque of the wheels, but it should'nt really interfere since it is just multiplying on top of them.

--------------------------------------------------

local Mouse = game.Players.LocalPlayer:GetMouse()
local carSeat = script.Parent.CarSeat.Value
local rwd = carSeat.Parent.Parent.RWD.RWD
local lwd = carSeat.Parent.Parent.LW.VS
local rrwd = carSeat.Parent.Parent.RW.VS
local RE = carSeat.Parent.RExhaust
local LE = carSeat.Parent.LExhaust
local sound = carSeat.Nitro


nitroFilled = true
nitroActive = false

game:GetService("UserInputService").InputBegan:connect(function(inputObject)
if inputObject.KeyCode == Enum.KeyCode.X then
if nitroFilled then
print("NITRO")
sound:Play()
nitroFilled = false
print("Nitro is empty!")
nitroActive = true
print("Nitro is active!")
wait(5)
nitroActive = false
print("Nitro is inactive!")
wait(10)
nitroFilled = true
print("Nitro is filled!")
end
end
end)


while wait() do
if nitroActive then
rwd.Torque = rwd.Torque*6
rrwd.Torque = rrwd.Torque*6
lwd.Torque = lwd.Torque*6
RE.Nitro.Enabled = true
LE.Nitro.Enabled = true
else
RE.Nitro.Enabled = false
LE.Nitro.Enabled = false
end
end
Report Abuse
austint30 is not online. austint30
Joined: 20 Mar 2010
Total Posts: 1482
12 Nov 2015 08:55 PM
Also, when I mean it doesn't work, I mean that it doesn't boost the car's torque. All the effects and sounds play like it should. It looks like it's having trouble multiplying the car's torque.
Report Abuse
austint30 is not online. austint30
Joined: 20 Mar 2010
Total Posts: 1482
13 Nov 2015 02:52 PM
Next day: still no replies.
Report Abuse
austint30 is not online. austint30
Joined: 20 Mar 2010
Total Posts: 1482
13 Nov 2015 04:33 PM
When it only works 50/50, it's really annoying. It should be working 100% every time. I just don't understand.
Report Abuse
TheBuilderGames is not online. TheBuilderGames
Joined: 28 Mar 2013
Total Posts: 211
13 Nov 2015 05:05 PM
Umm, does nitrofill have a local?
Report Abuse
austint30 is not online. austint30
Joined: 20 Mar 2010
Total Posts: 1482
13 Nov 2015 05:09 PM
I don't thing it matters if you write local on your variable if it is at the top of your script.
Report Abuse
austint30 is not online. austint30
Joined: 20 Mar 2010
Total Posts: 1482
13 Nov 2015 05:12 PM
I wrote local on the nitroFilled and nitroActive variables and nothing changed.

The car actually doesn't have a 50/50 chance. It pretty much only works once or twice and doesn't work after that.
Report Abuse
austint30 is not online. austint30
Joined: 20 Mar 2010
Total Posts: 1482
13 Nov 2015 06:15 PM
I need help guys. I can't figure it out and it's been about 24 hours already.
Report Abuse
austint30 is not online. austint30
Joined: 20 Mar 2010
Total Posts: 1482
13 Nov 2015 07:10 PM
Ok, it seems to be working now. I think the reason why it did this is because i used:

while wait() do
--code
end

instead of:

while true do
--code
wait()
end

--------------------------------------------------------

Anyway, here is the code, it works now.

local Mouse = game.Players.LocalPlayer:GetMouse()
local carSeat = script.Parent.CarSeat.Value
local rwd = carSeat.Parent.Parent.RWD.RWD
local lwd = carSeat.Parent.Parent.LW.VS
local rrwd = carSeat.Parent.Parent.RW.VS
local RE = carSeat.Parent.RExhaust
local LE = carSeat.Parent.LExhaust
local sound = carSeat.Nitro


local nitroFilled = true
local nitroActive = false


game:GetService("UserInputService").InputBegan:connect(function(inputObject)
if inputObject.KeyCode == Enum.KeyCode.X then
if nitroFilled and not nitroActive then
print("NITRO")
sound:Play()
nitroFilled = false
print("Nitro is empty!")
nitroActive = true
print("Nitro is active!")
wait(5)
nitroActive = false
print("Nitro is inactive!")
wait(10)
nitroFilled = true
print("Nitro is filled!")
else
print("Nitro is empty! Can't use Nitro yet!")
end
end
end)


while true do
if nitroActive and carSeat.Throttle == 1 then
sound.Volume = 1
rwd.Torque = rwd.Torque*5
rrwd.Torque = rrwd.Torque+5
lwd.Torque = lwd.Torque+5
RE.Nitro.Enabled = true
LE.Nitro.Enabled = true
else
nitroActive = false
sound.Volume = 0
RE.Nitro.Enabled = false
LE.Nitro.Enabled = false
end
wait()
end
Report Abuse
austint30 is not online. austint30
Joined: 20 Mar 2010
Total Posts: 1482
13 Nov 2015 07:14 PM
Never mind. It stopped working again. It just happens less often, but it still refuses to nitro sometimes.
Report Abuse
austint30 is not online. austint30
Joined: 20 Mar 2010
Total Posts: 1482
13 Nov 2015 07:49 PM
Can anybody help me?
Report Abuse
austint30 is not online. austint30
Joined: 20 Mar 2010
Total Posts: 1482
13 Nov 2015 07:54 PM
It's still failing to multiply the rwd.Torque by 5 and add to lwd and rrwd by 5.
Report Abuse
Jammer622 is not online. Jammer622
Joined: 19 Nov 2008
Total Posts: 1739
13 Nov 2015 09:13 PM
What are the classes of your variables?
Report Abuse
GrandSnaf is not online. GrandSnaf
Joined: 28 Mar 2015
Total Posts: 111
13 Nov 2015 09:21 PM
only 100%? pshaw, you don't need any help

Report Abuse
austint30 is not online. austint30
Joined: 20 Mar 2010
Total Posts: 1482
13 Nov 2015 10:02 PM
I do need help. It would work for a little bit and then suddenly just stop boosting the car's speed, and sometimes it would randomly start working again and of course stop working.
Report Abuse
austint30 is not online. austint30
Joined: 20 Mar 2010
Total Posts: 1482
13 Nov 2015 10:06 PM
Once the nitroFilled boolean is true it should be able to speed the car up again when the x button is pressed.
Report Abuse
Jammer622 is not online. Jammer622
Joined: 19 Nov 2008
Total Posts: 1739
13 Nov 2015 10:07 PM
How do I italicize the thing he glossed over?

The "What are the classes of your variables?" thing?

The "I don't remember what classes besides VehicleSeat use .Torque right off the top of my head why don't you fill me in so I can help you?" thing?

<3
Report Abuse
austint30 is not online. austint30
Joined: 20 Mar 2010
Total Posts: 1482
13 Nov 2015 10:19 PM
I moved the torque multiplying part of the script out of the while true do and into it's own function and just have the while true do call the function. Now, the nitro works about 80% of the time, much more than before, but still I want it 100% consistent. When my game ever get's released, I don't want people in the comments complaining the nitro isn't working.
Report Abuse
austint30 is not online. austint30
Joined: 20 Mar 2010
Total Posts: 1482
13 Nov 2015 10:20 PM
local Mouse = game.Players.LocalPlayer:GetMouse()
local carSeat = script.Parent.CarSeat.Value
local rwd = carSeat.Parent.Parent.RWD.RWD
local lwd = carSeat.Parent.Parent.LW.VS
local rrwd = carSeat.Parent.Parent.RW.VS
local RE = carSeat.Parent.RExhaust
local LE = carSeat.Parent.LExhaust
local sound = carSeat.Nitro


local nitroFilled = true
local nitroActive = false


game:GetService("UserInputService").InputBegan:connect(function(inputObject)
if inputObject.KeyCode == Enum.KeyCode.X then
if nitroFilled and not nitroActive then
print("NITRO")
sound:Play()
nitroFilled = false
print("Nitro is empty!")
nitroActive = true
print("Nitro is active!")
wait(5)
nitroActive = false
print("Nitro is inactive!")
wait(10)
nitroActive = false
nitroFilled = true
print("Nitro is filled!")
else
print("Nitro is empty! Can't use Nitro yet!")
end
end
end)

function Boost (PowerTorqueMultiply)
if rwd ~= nil or rrwd ~= nil or lwd ~= nil then
rwd.Torque = rwd.Torque*PowerTorqueMultiply
rrwd.Torque = rrwd.Torque*PowerTorqueMultiply
lwd.Torque = lwd.Torque*PowerTorqueMultiply
end
end


while true do
if nitroActive and carSeat.Throttle == 1 then
sound.Volume = 1
Boost(5)
RE.Nitro.Enabled = true
LE.Nitro.Enabled = true
else
nitroActive = false
sound.Volume = 0
RE.Nitro.Enabled = false
LE.Nitro.Enabled = false
end
wait()
end
Report Abuse
Jammer622 is not online. Jammer622
Joined: 19 Nov 2008
Total Posts: 1739
13 Nov 2015 10:25 PM
Man, I'm so glad austin answered my question so I could help him make the script 100% consistent <3
Report Abuse
austint30 is not online. austint30
Joined: 20 Mar 2010
Total Posts: 1482
13 Nov 2015 10:33 PM
I am using one class called UserInputService.

Sorry I didn't see your post from before.
Report Abuse
austint30 is not online. austint30
Joined: 20 Mar 2010
Total Posts: 1482
13 Nov 2015 10:38 PM
Also if this helps, I am using the SS3 Chassis on my car.
Report Abuse
Jammer622 is not online. Jammer622
Joined: 19 Nov 2008
Total Posts: 1739
13 Nov 2015 10:40 PM
Let me start over.

What are the Classes of the elements referenced "rwd", "rrwd", and "lwd" in your script?
Please refer to this list as an answering guide~
http://wiki.roblox.com/index.php?title=API:Class
Report Abuse
austint30 is not online. austint30
Joined: 20 Mar 2010
Total Posts: 1482
13 Nov 2015 10:48 PM
Oh ok. They are 'seats' which are connected to the wheels. These seats, you cannot sit on. They act as the engines. The main seat just controls their throttle and torque power.

rwd is the rear axle connecting both rear wheels.

rrwd is the right front axle that connects the front right wheel.

lwd is the left front axle that connects the front left wheel.

The rrwd and lwd are separate because the front wheels can steer.
Report Abuse
austint30 is not online. austint30
Joined: 20 Mar 2010
Total Posts: 1482
13 Nov 2015 10:50 PM
Also, if needed, here is the Main control script of the car.



--//INSPARE//--
--SS3.57--
script.Parent:WaitForChild("CC")
--Miscellaneous--
local player = game.Players.LocalPlayer
local carSeat = script.Parent.CarSeat.Value
local mouse = game.Players.LocalPlayer:GetMouse()
local rwd = carSeat.Parent.Parent.RWD.RWD
local lwd = carSeat.Parent.Parent.LW.VS
local rrwd = carSeat.Parent.Parent.RW.VS
gear = script.Parent.Gear
local carBody = carSeat.Parent.SportsCar
--Brakes--
local rb = carSeat.Parent.Parent.RWD
local lfb = carSeat.Parent.Parent.LW
local rfb = carSeat.Parent.Parent.RW
carSeat.MaxSpeed = 0
carSeat.TurnSpeed = 0
carSeat.Torque = 0


--TUNING--
tq = carSeat.Screen.FrontTorque.Value
rtq = carSeat.Screen.RearTorque.Value
cst = carSeat.Screen.Coast.Value
maxspeed = carSeat.Screen.MaxSpeed.Value
brakes = carSeat.Screen.BrakePower.Value --(0.1 - 1)
AccelerationCurve = carSeat.Screen.AccelerationCurve.Value

while wait() do

speed = carSeat.Velocity.Magnitude
rs = ((carSeat.Parent.Parent.Wheels.RL.Wheel.RotVelocity.Magnitude + carSeat.Parent.Parent.Wheels.RR.Wheel.RotVelocity.Magnitude)/2)/(2/carSeat.Parent.Parent.Wheels.RL.Wheel.Size.Y)
ftq = rtq/((speed/AccelerationCurve)+1) -- Adds a curve to the torque. In other words, the car will accelerate fast when moving slow, but start to decrease in acceleration power as it goes faster.

--mouse.KeyDown:connect(function (key)
-- key = string.lower(key)
-- if key ==
--end)

if script.Parent.TC.Value == true then
if rs > (20+speed) then
script.Parent.HUB.TCi.BorderSizePixel = 3
script.Parent.TC.On.Value = true
else
script.Parent.HUB.TCi.BorderSizePixel = 0
script.Parent.TC.On.Value = false
end
end

if script.Parent.Gear.Value == 1 then
script.Parent.HUB.Gear.Text = "D"

elseif script.Parent.Gear.Value == 0 then
script.Parent.HUB.Gear.Text = "N"

elseif script.Parent.Gear.Value == -1 then
script.Parent.HUB.Gear.Text = "R"
end
--//D//--
if gear.Value == 1 then
if script.Parent.TC.On.Value == true then
if carSeat.Throttle == 1 and script.Parent.CC.Value == true then
carSeat.Sound.Volume = 1
rwd.Torque = 0
lwd.Torque = 0
rrwd.Torque = 0
rwd.Throttle = 0
lwd.Throttle = 0
rrwd.Throttle = 0
elseif carSeat.Throttle == 1 and script.Parent.CC.Value == false then
carSeat.Sound.Volume = 1
rwd.Throttle = 0
rwd.Torque = 0
rwd.MaxSpeed = maxspeed
lwd.Throttle = 0
lwd.Torque = 0
lwd.MaxSpeed = maxspeed
rrwd.Throttle = 0
rrwd.Torque = 0
rrwd.MaxSpeed = maxspeed

elseif carSeat.Throttle == -1 then
carSeat.Sound.Volume = 0.5
script.Parent.CC.Value = false
rb.RB.CanCollide = true
rb.FB.CanCollide = true
lfb.RB.CanCollide = true
lfb.FB.CanCollide = true
rfb.RB.CanCollide = true
rfb.FB.CanCollide = true
wait(brakes)
rb.RB.CanCollide = false
rb.FB.CanCollide = false
lfb.RB.CanCollide = false
lfb.FB.CanCollide = false
rfb.RB.CanCollide = false
rfb.FB.CanCollide = false
wait()
elseif carSeat.Throttle == 0 and script.Parent.CC.Value == true then
carSeat.Sound.Volume = 0.5
rb.RB.CanCollide = false
rb.FB.CanCollide = false
lfb.RB.CanCollide = false
lfb.FB.CanCollide = false
rfb.RB.CanCollide = false
rfb.FB.CanCollide = false
elseif carSeat.Throttle == 0 and script.Parent.CC.Value == false then
carSeat.Sound.Volume = 0.5
rwd.Throttle = 0
rwd.Torque = cst
rwd.MaxSpeed = maxspeed
lwd.Throttle = 0
lwd.Torque = cst
lwd.MaxSpeed = maxspeed
rrwd.Throttle = 0
rrwd.Torque = cst
rrwd.MaxSpeed = maxspeed
rb.RB.CanCollide = false
rb.FB.CanCollide = false
lfb.RB.CanCollide = false
lfb.FB.CanCollide = false
rfb.RB.CanCollide = false
rfb.FB.CanCollide = false
end
end

if script.Parent.TC.On.Value == false then
if carSeat.Throttle == 1 and script.Parent.CC.Value == true then
carSeat.Sound.Volume = 1
rwd.Torque = ftq
lwd.Torque = tq
rrwd.Torque = tq
rwd.Throttle = 1
lwd.Throttle = 1
rrwd.Throttle = 1
elseif carSeat.Throttle == 1 and script.Parent.CC.Value == false then
carSeat.Sound.Volume = 1
rwd.Throttle = 1
rwd.Torque = ftq
rwd.MaxSpeed = maxspeed
lwd.Throttle = 1
lwd.Torque = tq
lwd.MaxSpeed = maxspeed
rrwd.Throttle = 1
rrwd.Torque = tq
rrwd.MaxSpeed = maxspeed

elseif carSeat.Throttle == -1 then
carSeat.Sound.Volume = 0.5
script.Parent.CC.Value = false
rb.RB.CanCollide = true
rb.FB.CanCollide = true
lfb.RB.CanCollide = true
lfb.FB.CanCollide = true
rfb.RB.CanCollide = true
rfb.FB.CanCollide = true
wait(brakes)
rb.RB.CanCollide = false
rb.FB.CanCollide = false
lfb.RB.CanCollide = false
lfb.FB.CanCollide = false
rfb.RB.CanCollide = false
rfb.FB.CanCollide = false
wait()
elseif carSeat.Throttle == 0 and script.Parent.CC.Value == true then
carSeat.Sound.Volume = 0.5
rb.RB.CanCollide = false
rb.FB.CanCollide = false
lfb.RB.CanCollide = false
lfb.FB.CanCollide = false
rfb.RB.CanCollide = false
rfb.FB.CanCollide = false
elseif carSeat.Throttle == 0 and script.Parent.CC.Value == false then
carSeat.Sound.Volume = 0.5
rwd.Throttle = 0
rwd.Torque = cst
rwd.MaxSpeed = maxspeed
lwd.Throttle = 0
lwd.Torque = cst
lwd.MaxSpeed = maxspeed
rrwd.Throttle = 0
rrwd.Torque = cst
rrwd.MaxSpeed = maxspeed
rb.RB.CanCollide = false
rb.FB.CanCollide = false
lfb.RB.CanCollide = false
lfb.FB.CanCollide = false
rfb.RB.CanCollide = false
rfb.FB.CanCollide = false
end
end
end
--//-//--

--//R//--
if gear.Value == -1 then
if carSeat.Throttle == 1 then
carSeat.Sound.Volume = 1
rwd.Throttle = -1
rwd.Torque = ftq/1.2
rwd.MaxSpeed = maxspeed/5
lwd.Throttle = -1
lwd.Torque = tq/1.2
lwd.MaxSpeed = maxspeed/5
rrwd.Throttle = -1
rrwd.Torque = tq/1.2
rrwd.MaxSpeed = maxspeed/5

elseif carSeat.Throttle == -1 then
carSeat.Sound.Volume = 0.5
rb.RB.CanCollide = true
rb.FB.CanCollide = true
lfb.RB.CanCollide = true
lfb.FB.CanCollide = true
rfb.RB.CanCollide = true
rfb.FB.CanCollide = true
wait(brakes)
rb.RB.CanCollide = false
rb.FB.CanCollide = false
lfb.RB.CanCollide = false
lfb.FB.CanCollide = false
rfb.RB.CanCollide = false
rfb.FB.CanCollide = false
wait()
elseif carSeat.Throttle == 0 then
carSeat.Sound.Volume = 0.5
rwd.Throttle = 0
rwd.Torque = cst
rwd.MaxSpeed = maxspeed
lwd.Throttle = 0
lwd.Torque = cst
lwd.MaxSpeed = maxspeed
rrwd.Throttle = 0
rrwd.Torque = cst
rrwd.MaxSpeed = maxspeed
rb.RB.CanCollide = false
rb.FB.CanCollide = false
lfb.RB.CanCollide = false
lfb.FB.CanCollide = false
rfb.RB.CanCollide = false
rfb.FB.CanCollide = false
end
end
--//-//--

--//N//--
if gear.Value == 0 then
if carSeat.Throttle == 1 then
carSeat.Sound.Volume = 1
rwd.Throttle = 0
rwd.Torque = cst
rwd.MaxSpeed = maxspeed
lwd.Throttle = 0
lwd.Torque = cst
lwd.MaxSpeed = maxspeed
rrwd.Throttle = 0
rrwd.Torque = cst
rrwd.MaxSpeed = maxspeed

elseif carSeat.Throttle == -1 then
carSeat.Sound.Volume = 0.5
rb.RB.CanCollide = true
rb.FB.CanCollide = true
lfb.RB.CanCollide = true
lfb.FB.CanCollide = true
rfb.RB.CanCollide = true
rfb.FB.CanCollide = true
wait(brakes)
rb.RB.CanCollide = false
rb.FB.CanCollide = false
lfb.RB.CanCollide = false
lfb.FB.CanCollide = false
rfb.RB.CanCollide = false
rfb.FB.CanCollide = false
wait()
elseif carSeat.Throttle == 0 then
carSeat.Sound.Volume = 0.5
rwd.Throttle = 0
rwd.Torque = cst
rwd.MaxSpeed = maxspeed
lwd.Throttle = 0
lwd.Torque = cst
lwd.MaxSpeed = maxspeed
rrwd.Throttle = 0
rrwd.Torque = cst
rrwd.MaxSpeed = maxspeed
rb.RB.CanCollide = false
rb.FB.CanCollide = false
lfb.RB.CanCollide = false
lfb.FB.CanCollide = false
rfb.RB.CanCollide = false
rfb.FB.CanCollide = false
end
end
--//-//--

if (carSeat.Steer == -1 or carSeat.Steer == 1 and carSeat.Throttle == 1) then
rwd.Torque = rwd.Torque*1.5
rrwd.Torque = rrwd.Torque*1.5
lwd.Torque = lwd.Torque*1.5
end

end
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image