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:

local prox = script.Parent.wheel.ProximityPrompt
local value = script.Parent.Value.Value

prox.Triggered:Connect(function()
    for i = 1, 10, 1 do

        if value == "false" then
            value = "true"
            script.Parent.wheel.CFrame = script.Parent.wheel.CFrame * CFrame.fromEulerAnglesXYZ(0.5,0,0) * CFrame.new(0, 0, 0)

            script.Parent.rod.CFrame = script.Parent.rod.CFrame * CFrame.fromEulerAnglesXYZ(0.5,0,0) * CFrame.new(0, 0, 0)
            wait(0.05)
        else
            for i = 1, 10, 1 do
                value = "false"
                script.Parent.wheel.CFrame = script.Parent.wheel.CFrame * CFrame.fromEulerAnglesXYZ(-0.5,0,0) * CFrame.new(0, 0, 0)

                script.Parent.rod.CFrame = script.Parent.rod.CFrame * CFrame.fromEulerAnglesXYZ(-0.5,0,0) * CFrame.new(0, 0, 0)
                wait(0.05)
            end

        end
    end
end)


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

local prox = script.Parent.wheel.ProximityPrompt
local value = script.Parent.Value.Value
local Wheel = script.Parent.wheel
local TS = game:GetService("TweenService")
local TI = TweenInfo.new(.5,Enum.EasingStyle.Quad)
prox.Triggered:Connect(function()
    if value then
        value = false
        TS:Create(Wheel,TI,{Orientation = vector3.new(0, 0, 90)}):Play()
    else if not value then
        value = true
        TS:Create(Wheel,TI,{Orientation = vector3.new(0, 0, -90)}):Play()
    end
end)

or

local prox = script.Parent.wheel.ProximityPrompt
local value = script.Parent.wheel.Value
prox.Triggered:Connect(function()
    if value == "false" then
        value = "true"
        for i = 1, 10, 1 do
            script.Parent.wheel.CFrame = script.Parent.wheel.CFrame * CFrame.fromEulerAnglesXYZ(0.5,0,0) * CFrame.new(0, 0, 0)
            wait(.05)
        end
    else
        value = "false"
        for i = 1, 10, 1 do
            script.Parent.wheel.CFrame = script.Parent.wheel.CFrame * CFrame.fromEulerAnglesXYZ(-0.5,0,0) * CFrame.new(0, 0, 0)
            wait(.05)
        end

    end
end)
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