So basically, I wanted a valve wheel, that when a player presses "E" once then it rotates to the right, and when the player presses "E" again it rotates to the left.
But in the current form of the script, it only rotates to the right, and doesn't change the value as it should change it.
The script:
01 | local prox = script.Parent.wheel.ProximityPrompt |
02 | local value = script.Parent.Value.Value |
03 |
04 | prox.Triggered:Connect( function () |
05 | for i = 1 , 10 , 1 do |
06 |
07 | if value = = "false" then |
08 | value = "true" |
09 | script.Parent.wheel.CFrame = script.Parent.wheel.CFrame * CFrame.fromEulerAnglesXYZ( 0.5 , 0 , 0 ) * CFrame.new( 0 , 0 , 0 ) |
10 |
11 | script.Parent.rod.CFrame = script.Parent.rod.CFrame * CFrame.fromEulerAnglesXYZ( 0.5 , 0 , 0 ) * CFrame.new( 0 , 0 , 0 ) |
12 | wait( 0.05 ) |
13 | else |
14 | for i = 1 , 10 , 1 do |
15 | value = "false" |
store the values as bools and use tween :) and you forgot to add another for loop to turn it left
01 | local prox = script.Parent.wheel.ProximityPrompt |
02 | local value = script.Parent.Value.Value |
03 | local Wheel = script.Parent.wheel |
04 | local TS = game:GetService( "TweenService" ) |
05 | local TI = TweenInfo.new(. 5 ,Enum.EasingStyle.Quad) |
06 | prox.Triggered:Connect( function () |
07 | if value then |
08 | value = false |
09 | TS:Create(Wheel,TI, { Orientation = vector 3. new( 0 , 0 , 90 ) } ):Play() |
10 | else if not value then |
11 | value = true |
12 | TS:Create(Wheel,TI, { Orientation = vector 3. new( 0 , 0 , - 90 ) } ):Play() |
13 | end |
14 | end ) |
or
01 | local prox = script.Parent.wheel.ProximityPrompt |
02 | local value = script.Parent.wheel.Value |
03 | prox.Triggered:Connect( function () |
04 | if value = = "false" then |
05 | value = "true" |
06 | for i = 1 , 10 , 1 do |
07 | script.Parent.wheel.CFrame = script.Parent.wheel.CFrame * CFrame.fromEulerAnglesXYZ( 0.5 , 0 , 0 ) * CFrame.new( 0 , 0 , 0 ) |
08 | wait(. 05 ) |
09 | end |
10 | else |
11 | value = "false" |
12 | for i = 1 , 10 , 1 do |
13 | script.Parent.wheel.CFrame = script.Parent.wheel.CFrame * CFrame.fromEulerAnglesXYZ(- 0.5 , 0 , 0 ) * CFrame.new( 0 , 0 , 0 ) |
14 | wait(. 05 ) |
15 | end |
16 |
17 | end |
18 | end ) |