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

How do I make the Slot slower than the Cover and how do I make it go back after click again?

This script is from Validark and others that are combined and fixed ALOT. But now, everytime I click it again, the slot goes forward and not backward and the cover like starts over and not go backward to like close it. This is the script and a video of what happened:

Script:

-- Combined script
local button = game.Workspace.Button
local slot = game.Workspace.Radio.Slot
local cover = game.Workspace.Radio.Cover
local home = cover.CFrame
debounce = false

function onClicked(button) --Supposed to work after you click the button and both the slot and cover come out at the same time
    spawn(function()
        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)

    local positionZValues = {-5.535, -6.635, -7.365} -- Z Value for Position (I wanted it to be from -5.535 to -7.365)
    if not debounce then
        debounce = true
        for a = 1,16 do --This "for" loop runs through each value of the table
            slot.Position = slot.Position + Vector3.new(0, 0, -0.114375) -- Only for Z value
            wait(.01)
        end
        debounce = false
    end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
---0.114375

Video Link of what happened and a little more explanation: https://www.youtube.com/watch?v=ZCKc4J6Cl5w&feature=youtu.be

1 answer

✓ Accepted answer

Your script needs to know if the slot is open or not. For this we are going to create the variable slot_Open. When it is true, the slot is open. When it is false, the slot is closed.

(slot_Open and 0.114375 or -0.114375) <-- That code makes it choose either positive or negative, depending on whether or not the slot is open

-- Combined script
local button = game.Workspace.Button
local slot = game.Workspace.Radio.Slot
local cover = game.Workspace.Radio.Cover
local home = cover.CFrame

local slot_Open = false
debounce = false

function onClicked(button) --Supposed to work after you click the button and both the slot and cover come out at the same time
    if not debounce then
    debounce = true
    spawn(function()
        if not slot_Open then
            for t = .12, 4.8, 0.18 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
        else
            for t = 4.8, .12, -0.18 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
    end)
wait(not slot_Open and .5 or 0)
    for a = 1,16 do --This "for" loop runs through each value of the table
        slot.Position = slot.Position + Vector3.new(0, 0, (slot_Open and 0.114375 or -0.114375)) -- Only for Z value
        wait(.01)
    end
    slot_Open = not slot_Open --Change it to open if it was closed, or closed if it was open
    debounce = false
    end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)

2 comments

0

This is what happened: https://www.youtube.com/watch?v=TidS1Jot8Jk&feature=youtu.be The cover went slower than the slot and it didn't go backward after the slot closed

0

Thanks for helping me, this is another video of what it looks like. There is a little problem with it though: https://www.youtube.com/watch?v=u6lCkr3WMtE

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