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

Did I mess up the CFrame.new method or what? (Not Working)

Asked by 8 years ago

I asked this before, but it is not doing what I want it to do. When I click the "Push" part, it doesn't even go down to the position I provided. Also, the ParticleEmitter didn't get enabled either. Here is the script:

-- Push up = -154.205, 22.023, -13.131
-- Push down = -154.205, 21.343, -13.131

push = game.Workspace.Pump.Push
air = game.Workspace.Pump.PumpOut.ParticleEmitter
debounce = false
pumpon = false

function onClicked()
    if debounce then return end
    debounce = true
    if pumpon then
        pumpon = true
        push.Position = Vector3.new(push.CFrame.X, 21.343, push.CFrame.Z) -- See below
        air.Enabled = true
        wait(1)
        air.Enabled = false
    else -- Your expression was redundant and likely a typo
        pumpon = false
       -- push.Position = push.CFrame(push.CFrame.X, 22.023, push.CFrame.Z)
    -- Needs to be a Vector3 for Position.
    push.Position = Vector3.new(push.CFrame.X, 22.023, push.CFrame.Z)
    -- Alternatively,
    -- push.CFrame = push.CFrame(push.CFrame.X, 22.023, push.CFrame.Z)
    end
    debounce = false -- You forgot to disable the debounce after the movement
end

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

1 answer

Log in to vote
0
Answered by
xAtom_ik 574 Moderation Voter
8 years ago

Problem

The problem is that if pumpon then detects if pumpon is true, which will never happen since your pumpon = true and pumpon = false are the wrong way around.

Solution

Switch around the pumpon = true and pumpon = false. You should end up with this:

-- Push up = -154.205, 22.023, -13.131
-- Push down = -154.205, 21.343, -13.131

push = game.Workspace.Pump.Push
air = game.Workspace.Pump.PumpOut.ParticleEmitter
debounce = false
pumpon = false

function onClicked()
    if debounce then return end
    debounce = true
    if pumpon then
        pumpon = false
        push.Position = Vector3.new(push.CFrame.X, 21.343, push.CFrame.Z) -- See below
        air.Enabled = true
        wait(1)
        air.Enabled = false
    else -- Your expression was redundant and likely a typo
        pumpon = true
       -- push.Position = push.CFrame(push.CFrame.X, 22.023, push.CFrame.Z)
    -- Needs to be a Vector3 for Position.
    push.Position = Vector3.new(push.CFrame.X, 22.023, push.CFrame.Z)
    -- Alternatively,
    -- push.CFrame = push.CFrame(push.CFrame.X, 22.023, push.CFrame.Z)

    end
    debounce = false -- You forgot to disable the debounce after the movement
end

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

I hope my answer helped you. Good luck in your future scripting!

0
Thanks for helping me man. It worked! RobotChitti 167 — 7y
Ad

Answer this question