Gui visibility not working

I’m making a simple script that when the player joins the game a set of images should be shown on the screen. I’m using the visibility boolean to try and make it possible but it doesn’t show up. Here is my code:

game.Players.PlayerAdded:Connect(function(player)
	local gui = player.PlayerGui.ImageCutscenes
	gui.Dialogue1.Visible = true
	wait(5)
	gui.Dialogue1.Visible = false
	gui.Dialogue2.Visible = true
	wait(5)
	gui.Dialogue2.Visible = false
	gui.Dialogue3.Visible = true
	wait(5)
	gui.Dialogue3.Visible = false
	gui.Dialogue4.Visible = true
	wait(5)
	gui.Dialogue4.Visible = false
	gui.Dialogue5.Visible = true
	wait(5)
	gui.Dialogue5.Visible = false
	gui.Dialogue6.Visible = true
	wait(5)
	gui.Dialogue6.Visible = false
	gui.Dialogue7.Visible = true
	wait(5)
	gui.Dialogue7.Visible = false
end)

I’ve tried in both server and local scripts but it isn’t working, even with print statements.

you should probably put this inside a LocalScript instead of a PlayerAdded function, You should also wait for the object as you are firing the code when the Player joins the game and not when the Item is added to the , also, this is very inefficient way of doing this, you should instead do:

local gui = player.PlayerGui:WaitForChild("ImageCutscenes") -- waits for object

for index = 1,#ImageCutscenes:GetChildren() do -- fires for the number of objects within the ScreenGui
    pcall(function() -- This is so it doesn't cause errors to the code
        gui[i].Visible = true
        gui[i-1].Visible = false
    end)
    task.wait(5) --improved version of wait()
end

I fixed some stuff up and put it in a local script but it still doesn’t fire:

local player = game.Players.LocalPlayer
local gui = player.PlayerGui:WaitForChild("ImageCutscenes") -- waits for object

for index = 1,#gui:GetChildren() do -- fires for the number of objects within the ScreenGui
	pcall(function() -- This is so it doesn't cause errors to the code
		gui[index].Visible = true
		gui[index-1].Visible = false
	end)
	task.wait(5) --improved version of wait()
end