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

What am I doing wrong here? *Edited*

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

3 comments

0

Any errors in the output?

0

Change your elseif to just an else

0

@Skootakip, no there isn't any errors

1 answer

Your issues are in the OnClicked,

function onClicked()
    if debounce then return end
    debounce = true
    if pumpon then
        pumpon = false
        pump.Position = pump.CFrame(pump.CFrame.X, 21.533, pump.CFrame.Z)
    else -- Your expression was redundant and likely a typo
        pumpon = true
    	pump.Position = pump.CFrame(pump.CFrame.X, 22.023, pump.CFrame.Z)
    	air.Enabled = true
    	wait(1)
    	air.Enabled = false
    end
    debounce = false -- You forgot to disable the debounce after the movement
end

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