I know you cant import .GIF Files into Roblox Studio cuz you know that would be all too easy, so my alternative is just importing frame by frame and making a GIF the hard way. Currently i am only testing with 42 picture frames from the original GIF.
Idea is press a button which are linked to 6 different parts that contain an image. If i could i would want to send them to the ReplicatedStorage and then back into the Workspace, but this method is way too advance for me at the moment. So ive been trying to make the Decal transparent and back to a solid in the matter of 0.03 seconds. Which seems to work fine but if you click the button again it obviously speeds the process up. I thought about adding a debounce but im not sure how to script that exactly for it to work properly.
All and all im just trying to make the decal disappear and have another reappear in a matter of half a second.
For the sake of this forum and repeated coding i have cut the 42 frames into 6 frames. Heres my current code:
local script = script.Parent.Parent local image1 = script.Parent.image1 local image2 = script.Parent.image2 local image3 = script.Parent.image3 local image4 = script.Parent.image4 local image5 = script.Parent.image5 local image6 = script.Parent.image6 n = 6 function GIFOn() while true do n = 6 if image1.Decal.Transparency == 1 then image1.Decal.Transparency = 0 else image1.Decal.Transparency = 1 end wait(0.03) if image2.Decal.Transparency == 1 then image2.Decal.Transparency = 0 else image2.Decal.Transparency = 1 end wait(0.03) if image3.Decal.Transparency == 1 then image3.Decal.Transparency = 0 else image3.Decal.Transparency = 1 end wait(0.03) if image4.Decal.Transparency == 1 then image4.Decal.Transparency = 0 else image4.Decal.Transparency = 1 end wait(0.03) if image5.Decal.Transparency == 1 then image5.Decal.Transparency = 0 else image5.Decal.Transparency = 1 end wait(0.03) if image6.Decal.Transparency == 1 then image6.Decal.Transparency = 0 else image6.Decal.Transparency = 1 end wait(0.03) end end script.ClickDetector.MouseClick:connect(GIFOn)
Hey there DSGx,
Your method is quite verbose. If I may, I would like to suggest a better solution. First, though, you should really read the Lua 5.1 manual, as well as NoahWillCode's Clean and Tidy.
Carrying on, let's set up a simpler, more easily extensible system. Delete all the extra decals, leaving only one. Name that last decal Display
.
Erase the entire script. We will now create several variables representing the ClickDetector, the Decal, and a bool representing the state of the display, as well as something called a table, which will store all the images that constitute the GIF. Write like so:
local Display = script.Parent:WaitForChild("Display"); local Detector = script.Parent.Parent:WaitForChild("ClickDetector"); local IsActive = false; local Images = { ImageID1; ImageID2; ImageID3; -- ... and so on... };
If the first three image IDs are 1337, 9001, and 1234, we would write the table as follows:
local Images = { 1337; 9001; 1234; };
Next, let's write a function that runs when the given button is pressed and connect it to the ClickDetector's MouseClick event:
local function ButtonClicked() -- Only run if IsActive is false if (not IsActive) then IsActive = true; -- ... IsActive = false; end; end; Detector.MouseClick:Connect(ButtonClicked);
Alright, that's a start. Let's continue by changing the images that display on the screen:
local function ButtonClicked() -- Only run if IsActive is false if (not IsActive) then IsActive = true; -- This goes through each image in Images and changes the Decal ID accordingly for i, imageID in ipairs(Images) do Display.Texture = "rbxassetid://" .. imageID; wait(0.03); end; -- Set the display texture to... nothing. Display.Texture = " "; wait(1); IsActive = false; end; end; Detector.MouseClick:Connect(ButtonClicked);
There! Now, if we click the button, each image in Image will be displayed sequentially, not unlike a GIF would be. Here's the entire script:
local Display = script.Parent:WaitForChild("Display"); local Detector = script.Parent.Parent:WaitForChild("ClickDetector"); local IsActive = false; local Images = { 1337; 9001; 1234; }; local function ButtonClicked() -- Only run if IsActive is false if (not IsActive) then IsActive = true; -- This goes through each image in Images and changes the Decal ID accordingly for i, imageID in ipairs(Images) do Display.Texture = "rbxassetid://" .. imageID; wait(0.03); end; -- Set the display texture to... nothing. Display.Texture = " "; wait(1); IsActive = false; end; end; Detector.MouseClick:Connect(ButtonClicked);
Now, all you have to do is populate Images with each ID for your GIF. You can now easily modify and extend this as you so please; plus, it looks a lot cleaner.
I hope this helps. Have a nice day DSGx, and best of luck with your project!
Cheers,
tkcmdr