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

why does my valve wheel only turn to the right?

Asked by 2 years ago
Edited 2 years ago

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:

01local prox = script.Parent.wheel.ProximityPrompt
02local value = script.Parent.Value.Value
03 
04prox.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"
View all 24 lines...

1 answer

Log in to vote
0
Answered by
Puppynniko 1059 Moderation Voter
2 years ago

store the values as bools and use tween :) and you forgot to add another for loop to turn it left

01local prox = script.Parent.wheel.ProximityPrompt
02local value = script.Parent.Value.Value
03local Wheel = script.Parent.wheel
04local TS = game:GetService("TweenService")
05local TI = TweenInfo.new(.5,Enum.EasingStyle.Quad)
06prox.Triggered:Connect(function()
07    if value then
08        value = false
09        TS:Create(Wheel,TI,{Orientation = vector3.new(0, 0, 90)}):Play()
10    else if not value then
11        value = true
12        TS:Create(Wheel,TI,{Orientation = vector3.new(0, 0, -90)}):Play()
13    end
14end)

or

01local prox = script.Parent.wheel.ProximityPrompt
02local value = script.Parent.wheel.Value
03prox.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
18end)
0
Not sure why, but these scripts won't rotate the valve wheel Kisferenc 47 — 2y
0
what are you rotating, the wheel? or other things connected by constraints Puppynniko 1059 — 2y
Ad

Answer this question