Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

why does my valve wheel only turn to the right?

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

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)

2 comments

0

Not sure why, but these scripts won't rotate the valve wheel

0

what are you rotating, the wheel? or other things connected by constraints

This discussion is preserved as it was. New answers, comments, and votes are closed.