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

car gear script won't change gears. ?

Asked by 5 years ago

I'm trying to make a script that does the following things -add 4 gears to a car -gear 4 only works if you have a gamepass - all shifted with z/x or L1/R1

the script is part of my localcarscript that gets copied into the player's playergui folder when it is driven.

here is my code so far

1local player = game.Players.LocalPlayer
2local stats = car:WaitForChild("Configurations")
3local CAS = game:GetService("ContextActionService")
4local staticspeed = stats.Speed.Value
5local MPS = game:GetService("MarketplaceService")
6local cargear = script.Gear.Value
01function geardown(name,state,action)
02    if state == Enum.UserInputState.Begin then
03 
04    elseif state == Enum.UserInputState.End then
05        cargear = cargear - 1
06        if cargear < 1 then
07            cargear = 1
08        end
09 
10    end
11end
12 
13function gearup(name,state,action)
14    if state == Enum.UserInputState.Begin then
15 
View all 41 lines...
1CAS:BindActionToInputTypes("GearDown", geardown, true, Enum.KeyCode.Z, Enum.KeyCode.ButtonL1)
2CAS:SetPosition("GearDown", UDim2.new(.25,0,.25,0))
3CAS:SetTitle("GearDown", "Down")
4CAS:BindActionToInputTypes("GearUp", gearup, true, Enum.KeyCode.X, Enum.KeyCode.ButtonR1)
5CAS:SetPosition("GearUp", UDim2.new(.10,0,.25,0))
6CAS:SetTitle("GearUp", "Up")

when i run it in studio there is no output, and the car stays in gear 3 (which is the default value of the gear integer)

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Line 6: local cargear = script.Gear.Value

This line returns an integer. Not the Value property of script.Gear, just an integer. When you change it like cargear = x, you aren't updating the Value property of script.Gear, you're just updating that integer.

You need 'cargear' to be script.Gear, and change it with cargear.Value = x.

01local cargear = script.Gear
02 
03function gearup(name,state,action)
04    if state == Enum.UserInputState.Begin then
05 
06    elseif state == Enum.UserInputState.End then
07        cargear.Value = cargear.Value + 1
08        if cargear.Value > 4 then
09            cargear.Value = 4
10        end
11 
12    end
13end

as opposed to

01local cargear = script.Gear.Value
02 
03function gearup(name,state,action)
04    if state == Enum.UserInputState.Begin then
05 
06    elseif state == Enum.UserInputState.End then
07        cargear = cargear + 1
08        if cargear > 4 then
09            cargear = 4
10        end
11 
12    end
13end

Sorry if that explanation's overkill; I find this (quite common) issue quite finicky to put into words.

P.S. :connect() is deprecated, use :Connect() instead.

Ad

Answer this question