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

How to make a ImageButton only allowed to be clicked once.

Alright, so i made a script for my Menu_Gui, which is you know. The options to Play, Customize Character Looks, and Look at Options to change gameplay experience, etc.

When someone clicks "Play", it brings up a notification i made. That let's them know they will be locked into first person. That once clicking "OK" they will be locked into first person.

This is the script for the button i made. If you're wondering why i did all the transparency, and didn't use a variable, and didn't just use *1. I was bored. I felt like typing each line with transparency change.

function onClicked()
game.Players.LocalPlayer.CameraMode = "LockFirstPerson"
print("FirstPersonisLocked")

script.Parent.Parent.Parent.BackgroundTransparency = 0
wait(0.1)
script.Parent.Parent.Parent.BackgroundTransparency = 0.1
wait(0.1)
script.Parent.Parent.Parent.BackgroundTransparency = 0.2
wait(0.1)
script.Parent.Parent.Parent.BackgroundTransparency = 0.3
wait(0.1)
script.Parent.Parent.Parent.BackgroundTransparency = 0.4
wait(0.1)
script.Parent.Parent.Parent.BackgroundTransparency = 0.5
wait(0.1)
script.Parent.Parent.Parent.BackgroundTransparency = 0.6
wait(0.1)
script.Parent.Parent.Parent.BackgroundTransparency = 0.7
wait(0.1)
script.Parent.Parent.Parent.BackgroundTransparency = 0.8
wait(0.1)
script.Parent.Parent.Parent.BackgroundTransparency = 0.9
wait(0.1)
script.Parent.Parent.Parent.BackgroundTransparency = 1
wait(0.1)

script.Parent.Parent.Parent.Parent:remove()
print("everything removed")
end

script.Parent.MouseButton1Click:connect(onClicked)

Is there a way i could make this be only allowed to be pressed once? Because if i press the button multiple times. It makes this flicker affect, because every time i click it, it's restarting this whole function and script itself. Is there a way i can make it where once you click it, the script works, and then you're not able to keep clicking this button.

Thanks in advanced if you answer!

1 answer

✓ Accepted answer

Let me simplify the code for you

local clicked = false
function Clicked()
if clicked == false then
clicked = true
 for i=0, 1, .1 do
script.Parent.Parent.Parent.BackgroundTransparency = i
wait()
end
script.Parent.Parent.Parent.Parent:remove()
print("everything removed")
end
end

script.Parent.MouseButton1Click:connect(Clicked)

5 comments

0

I wasn't asking for simplified code. I made my code like that, because i was bored and i felt like doing all that. I can work my games scripts how i would like, but thank you. I'd rather get an answer pertaining to my question i asked. Thanks though!

0

I also answered it while simplifying

0

its answered try it out. before you start lowering peoples points.

0

I actually didn't down your reputation. Talk to someone else about that, i never vote up/down on reps. But thanks for the response.

0

honestly i was speaking in general shouldve mentioned that

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