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

What am I doing wrong here?

I haven't scripted for a while and I am actually a beginner still. Well, anyway, I am working on a script where when I click the "Push" it will go up to the position I put and when I click it again, it will go down to the position that I put plus making theParticleEmitter enabled as well for just a second and then off. I hope you understand what I mean.

-- 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 = push.CFrame(push.CFrame.X, 21.343, push.CFrame.Z)
        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)
    end
    debounce = false -- You forgot to disable the debounce after the movement
end

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

1 answer

✓ Accepted answer

First, it helps if you give errors and output, and explain what is actually happening.

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

The issue is that you

  • Failed to construct a CFrame properly using CFrame.new
  • Tried to set Position to a CFrame value.

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