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

How do I make this script rotate backward after I click it again? (Added debounce, but not working)

How do I make this go back after it goes to the last rotations which is 90? Like I want it where the x value for the rotation stops there and when I click it again, it goes backward. This is the script of BlueTaslem:

--BlueTaslem Answered Script (Thank you)
local cover = game.Workspace.Radio.Cover
local home = cover.CFrame

function onClicked()
for t = 0, 4.8, 0.03 do
    wait(0.001)
    local v = math.cos(t / 4.8 * math.pi) * 45 + 90 + 45
    cover.CFrame = home
    cover.Rotation = Vector3.new(v, 0, 180)
end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

Added Debounce! It didn't work and did I do it right?

Link to what the problem is: https://www.youtube.com/watch?v=ZzG9NHdR81o&feature=youtu.be

--BlueTaslem Answered Script with LordDragonZord (Thank you)
local cover = game.Workspace.Radio.Cover
local rot = cover.Rotation
debounce = false

function onClicked()
if not debounce then
	debounce = true
if rot == cover.Rotation then
	for t = 0, 4.8, 0.03 do
    wait(0.001)
    local v = math.cos(t / 4.8 * math.pi) * 45 + 90 + 45
    cover.CFrame = cover.CFrame*CFrame.Angles(v,0,0)
end
end
else
if not debounce then
	debounce = true
    for t = 0, 4.8, 0.03 do
    wait(0.001)
    local v = math.cos(-(t / 4.8) * math.pi) * 45 + 90 + 45
    cover.CFrame = cover.CFrame*CFrame.Angles(v,0,0)
	debounce = false
end
end
end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

4 comments

0

You won't learn by stealing other people's code...

0

I didn't. I made like a huge script, and Validark made it shorter, and BlueTaslem made it shorter as well.

0

Well, to move it back i would assume you would just rotate it by -v and -180, but idk because that math stuff is confusing

0

Ikr. I had to use my basics way, which was Vector3.new() like bunch of times with the scale in it. Luckily, Validark made it better using the table method and BlueTaslem made it even smaller and well, better with the rotations I think. But both of them were good and I gotta to thank them for it.

1 answer

Simple, save what the original rotation was and change it back to that. Have a


#Final Product

--BlueTaslem Answered Script (Thank you)
local cover = game.Workspace.Radio.Cover
local rot = cover.Rotation

function onClicked()
if rot == cover.Rotation then
for t = 0, 4.8, 0.03 do
    wait(0.001)
    local v = math.cos(t / 4.8 * math.pi) * 45 + 90 + 45
    cover.CFrame = cover.CFrame*CFrame.Angles(v,0,0)
end
else
    cover.CFrame = cover.CFrame*CFrame.Angles(rot)
end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)



Hope it helps!(If it doesn't work, comment plz!)


If you want the animation effect:

--BlueTaslem Answered Script (Thank you)
local cover = game.Workspace.Radio.Cover
local rot = cover.Rotation

function onClicked()
if rot == cover.Rotation then
for t = 0, 4.8, 0.03 do
    wait(0.001)
    local v = math.cos(t / 4.8 * math.pi) * 45 + 90 + 45
    cover.CFrame = cover.CFrame*CFrame.Angles(v,0,0)
end
else
	for t = 0, 4.8, 0.03 do
    wait(0.001)
    local v = math.cos(-(t / 4.8) * math.pi) * 45 + 90 + 45
    cover.CFrame = cover.CFrame*CFrame.Angles(v,0,0)
end
end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

1 comment

0

I put it there, but there was a red line under else, and the error was: 21:06:44.082 - Workspace.Radio.Cover.BlueTaslem:11: 'end' expected (to close 'for' at line 7) near 'else'

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