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

Screengui getting a decal to change? [[SOLVED]]

It sounds simple right? Well I have tried time over time. I want to click on a screengui and when I click on it the decal changes to a light switch that is on and the light comes on. Than I want to click it again and it change to the off light switch. Anybody mind helping me write the script it should be very simple.

P.S. It is an ImageButton on the Screengui that changes decals.

This is what I have so far:

On=false 
function onClicked() 
if On then On=false else 
On=true 
while On do
	
	script.Parent.Image = Image.new("rbxassetid://173364351")
	wait(0.1)	

end
end
end


script.Parent.ClickDetector.MouseClick:connect(onClicked)

That above is the enabler but is there a way to make it so for example I can disable it and enable. I guess I am just kind of confused if someone can clear it up for me.

1 answer

✓ Accepted answer

First of all, there are alot of errors here.

  1. if On then On=false else This, this is just, well, confusing too look at XD.

  2. while On do has been changed to while On==true dobecause that doesn't make sense either

  3. You never do Image.new(), thats not even a thing, you just do script.Parent.Image = "http://www.roblox.com/asset/?id= image id" .

  4. Finally, the worst error here. script.Parent.ClickDetector.MouseClick:connect(onClicked) When you click a GUI button, its not a ClickDetector... thats for a part, not for a GUI. And you don't use MouseClickon a GUI, you use MouseButton1Down.

Please check your scripting or learn some scripting.

Your welcome

On=false 
function onClicked() 
if On == false then
On = true 
while On == true do

    script.Parent.Image = "http://www.roblox.com/asset/?id=173364351"
    wait(0.1)   
end
end
end


script.Parent.MouseButton1Down:connect(onClicked)

1 comment

0

Alright thank you very much, that helps a lot. I am starting to lose my thoughts that is why my script sucks. I forgot about the MouseButton1down and actually had it in my original script. I got the beginning part from a friend and never understood it but hoped it worked. The middle part I tried to do myself. I am actually still learning and this has defiantly helped me along.

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