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

How to script a button that has 2 events? [closed]

Asked by 7 years ago

Heres what i want to know how do i make a script on a button like when i click it will do the events then i want to click the button again to revert the events

Closed as Not Constructive by OldPalHappy

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

1 answer

Log in to vote
0
Answered by
Gridant 15
7 years ago

This is the simplest thing I could think of. Just change the script around to do what you want it to do, these are just the basics of doing and undoing with one button. If you need further help just ask, I'll reply asap.

script:

local Button = script.Parent

local status = 0 --1 = on (item spawned) , 0 = off (item is not spawned)

function spawnobject()

if status == 0 then

    wait(1)

    status = 1 

    local ball = Instance.new("Part")

    ball.Parent = game.Workspace

    ball.Position = Button.Position

    ball.Shape = "Ball"

    ball.Size = Vector3.new(5,5,5)

    ball.Name = "SpawnedBall"

end

end

Button.ClickDetector.MouseClick:connect(spawnobject)

function despawnobject()

if status == 1 then

    wait(1)

    status = 0

    game.Workspace:FindFirstChild("SpawnedBall"):Destroy()

end

end

Button.ClickDetector.MouseClick:connect(despawnobject)

0
Gridant, why not make it all under one single function? Robertandy11 103 — 7y
Ad