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

How to script a button that has 2 events?

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

1 answer

✓ Accepted answer

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)

1 comment

0

Gridant, why not make it all under one single function?

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