Issue with changing 2 images in same script with button

so only 1 works when you click on the button 1 image changes to it but the other doesn’t.

script:

local button = script.Parent

local images = {player.PlayerGui.ScreenGui.Main.Settings.BackgroundImageSet,
player.PlayerGui.ScreenGui.Main.Games.BackgroundImageGame}

button.MouseButton1Up:Connect(function()
	for i,v in ipairs(images) do
		v.Image = "rbxassetid://9567131795"
	end
end)```


Output says nothing
1 Like

Mouse1ButtonClick

Can you send an image of the explorer? Your paths that you made with dot operators might be non functional (for one).

explorer

That’s only one of the frames, what about the other one?

explorer

You could try preloading the image or instead just refer to the paths in two separate variables and set img1.Image and img2.Image as there are only 2 images and this is unnecessary. :+1:

Im not the best coder how would you preload it

1 Like

PreloadService (i think that’s the service’s name)

1 Like

How… Would I do it?

[Char limit]

Use its functions. That’s pretty much it. Also, not PreloadService, accident. ContentProvider | Roblox Creator Documentation Use ContentProvider as PreloadService is fake and I didn’t mean to say that.

1 Like

Septonomic is correct. The PlayerGui is cloned from StarterGui so it might take a second.

Game:GetService("ContentProvider"):Preload("http://www.roblox.com/asset/?id=9567131795")

does this go on the top 1st line?

It can, also I think I gave you the soon to be deprecated format, use PreloadAsync. Something like…

local ContentProvider = game:GetService("ContentProvider")

local asset = "rbxassetid://9567131795"

ContentProvider:PreloadAsync(asset)

local button = script.Parent

local images = {player.PlayerGui.ScreenGui.Main.Settings.BackgroundImageSet,
player.PlayerGui.ScreenGui.Main.Games.BackgroundImageGame}

button.MouseButton1Up:Connect(function()
	for i,v in ipairs(images) do
		v.Image = (asset)
	end
end)

didnt work the output said:

Unable to cast to Array

I made a quick reproduction of your directory and it seemed to replace both images with the asset, see if this works…

Game:GetService("ContentProvider"):PreloadAsync("http://www.roblox.com/asset/?id=9567131795")
local button = script.Parent

local images = {player.PlayerGui.ScreenGui.Main.Settings.BackgroundImageSet,
player.PlayerGui.ScreenGui.Main.Games.BackgroundImageGame}

button.MouseButton1Up:Connect(function()
	for i,v in ipairs(images) do
		v.Image = "rbxassetid://9567131795"
	end
end)

same output again no images change…