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

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

Asked by 10 years ago

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

Log in to vote
2
Answered by 10 years ago

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)
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! Cataclyzmic 93 — 10y
0
I also answered it while simplifying DragonSkyye 517 — 10y
0
its answered try it out. before you start lowering peoples points. DragonSkyye 517 — 10y
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. Cataclyzmic 93 — 10y
0
honestly i was speaking in general shouldve mentioned that DragonSkyye 517 — 10y
Ad

Answer this question