GUI Images not changing properly

  1. What do you want to achieve?
    I would like the ImageLabel (denoted as “img”) to change 4 times. It should be invisible at first, then when prompted (clicking "txtbut"or “imgbut”), reveal itself. Pressing the Next (denoted as “nextbut”) button will change the image once, then pressing it again will change it , and pressing it a final time will close it and make it invisible.
  2. What is the issue?
    The Image label does not change the 3rd time, but when clicked again, it closes. It essentially skips lines 21-23.
  3. What solutions have you tried so far?
    I have tried adding a Wait() at the end of each loop, but it did not work. I tried on the Roblox Discord, and they told me to use PlayerGUI (which I have put, but I am not sure how to make use of this). I also made sure that the Image was available by putting it in a separate script (as well as in Properties), and it worked, which leads me to the conclusion that there is an issue with the conditional block itself. There are also no errors in the output.
    Code:
local plr = game.Players.LocalPlayer
local plrgui = plr.PlayerGui
local imgbut = script.Parent.Parent.HowToPlay
local txtbut = script.Parent.Parent.HowToPlay.HowToPlayText
local img = script.Parent
local nextbut = script.Parent.Next
img.Transparency = 1
img.BackgroundTransparency = 1
img.ImageTransparency = 1
nextbut.Transparency = 1
nextbut.BackgroundTransparency = 1
nextbut.ImageTransparency = 1
local function tutorial()
	img.ImageTransparency = 0
	nextbut.ImageTransparency = 0
	img.Image = "rbxassetid://10477538300"
	wait(0.5)
	nextbut.MouseButton1Click:Connect(function()
		img.Image = "rbxassetid://10477532907"
		wait(0.5)
		nextbut.MouseButton1Click:Connect(function()
			img.Image = "rbxassetid://10477484354"
			wait(0.5)
			nextbut.MouseButton1Click:Connect(function()
				img.Transparency = 1
				img.BackgroundTransparency = 1
				img.ImageTransparency = 1
				nextbut.Transparency = 1
				nextbut.BackgroundTransparency = 1
				nextbut.ImageTransparency = 1
			end)
		end)
	end)
end
imgbut.MouseButton1Click:Connect(tutorial)
txtbut.MouseButton1Click:Connect(tutorial)

try using http://www.roblox.com/asset/?id= instead of rbxassetid://

Sorry, this still didn’t work. I think it has something to do with the second nextbut.MouseButton1Click:Connect(function() part

Try this:

local plr = game:GetService("Players").LocalPlayer
local plrgui = plr:WaitForChild("PlayerGui")
local img = script.Parent
local imgbut = img.Parent:WaitForChild("HowToPlay")
local txtbut = imgbut:WaitForChild("HowToPlayText")

local nextbut = img:WaitForChild("Next")
local Clicks = 0

img.Transparency = 1
img.BackgroundTransparency = 1
img.ImageTransparency = 1
nextbut.Transparency = 1
nextbut.BackgroundTransparency = 1
nextbut.ImageTransparency = 1

local function tutorial()
	
	if Clicks==0 then
		img.ImageTransparency = 0
		nextbut.ImageTransparency = 0
		img.Image = "rbxassetid://10477538300"
	elseif Clicks==1 then	
		img.Image = "rbxassetid://10477532907"
	elseif Clicks==2 then
		img.Image = "rbxassetid://10477484354"
	else
		img.Transparency = 1
		img.BackgroundTransparency = 1
		img.ImageTransparency = 1
		nextbut.Transparency = 1
		nextbut.BackgroundTransparency = 1
		nextbut.ImageTransparency = 1
	end
	Clicks += 1

end

imgbut.MouseButton1Click:Connect(tutorial)
txtbut.MouseButton1Click:Connect(tutorial)
1 Like

use tables

local plr = game.Players.LocalPlayer
local plrgui = plr.PlayerGui
local imgbut = script.Parent.Parent.HowToPlay
local txtbut = script.Parent.Parent.HowToPlay.HowToPlayText
local img = script.Parent
local nextbut = script.Parent.Next
img.Transparency = 1
img.BackgroundTransparency = 1
img.ImageTransparency = 1
nextbut.Transparency = 1
nextbut.BackgroundTransparency = 1
nextbut.ImageTransparency = 1

local Images = {
	"rbxassetid://10477538300",
	"rbxassetid://10477532907",
	"rbxassetid://10477484354"
}
local CurrentImage = 1

local function nextPage()
	img.ImageTransparency = 0
	nextbut.ImageTransparency = 0
	CurrentImage += 1
	
	if CurrentImage > #Images then
		img.BackgroundTransparency = 1
		img.ImageTransparency = 1
		nextbut.Transparency = 1
		nextbut.BackgroundTransparency = 1
		nextbut.ImageTransparency = 1

		CurrentImage = 1
	else
		img.Image = Images[CurrentImage]
	end
end

imgbut.MouseButton1Click:Connect(nextPage)
txtbut.MouseButton1Click:Connect(nextPage)
1 Like

It works, but in the wrong way. It’s meant to change when you click “nextbut” not “imgbut”, so its only changing when you press “imgbut”.

Sadly, this didn’t work either. It returned the error:
“Players.ValtryekRBLX.PlayerGui.Book.HowToPlayFrame.TutorialImages.LocalScript:35: Incomplete statement: expected assignment or a function call”
Also, everything started as visible, and not invisible, probably stemming from this error.

Oof, it still doesn’t work. It starts at the 2nd image and the next button doesn’t do anything, only imgbut/txtbut changes the main img. It starts on the 2nd image, and clicking img/txt button will change the image to 3rd image, and clicking it again will close it. Frankly, I don’t blame you, my code is kind of clunky and weird.

local plr = game.Players.LocalPlayer
local plrgui = plr.PlayerGui
local imgbut = script.Parent.Parent.HowToPlay
local txtbut = script.Parent.Parent.HowToPlay.HowToPlayText
local img = script.Parent
local nextbut = script.Parent.Next
img.Transparency = 1
img.BackgroundTransparency = 1
img.ImageTransparency = 1
nextbut.Transparency = 1
nextbut.BackgroundTransparency = 1
nextbut.ImageTransparency = 1

local Images = {
	"rbxassetid://10477538300",
	"rbxassetid://10477532907",
	"rbxassetid://10477484354"
}
local CurrentImage = 0

local function nextPage()
	img.ImageTransparency = 0
	nextbut.ImageTransparency = 0
	CurrentImage += 1
	
	if CurrentImage > #Images then
		img.BackgroundTransparency = 1
		img.ImageTransparency = 1
		nextbut.Transparency = 1
		nextbut.BackgroundTransparency = 1
		nextbut.ImageTransparency = 1

		CurrentImage = 0
	else
		img.Image = Images[CurrentImage]
	end
end

imgbut.MouseButton1Click:Connect(nextPage)
txtbut.MouseButton1Click:Connect(nextPage)

my bad, its fixed now

1 Like

Great, it works! However, the image is meant to change when you press “nextbut” not “imgbut” or “txtbut”. The script is meant to trigger with “imgbut” or “txtbut”, and img must change with nextbut

just replace txtbut to nextbut on the last line

1 Like

Perfect, this worked wonders! Thank you so much for your help, and your time (this took quite a while!)