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

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

Asked by 10 years ago

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

Log in to vote
0
Answered by 10 years ago

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)
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. Ffbryce1 0 — 10y
Ad

Answer this question