Saving Images Visibilty (I'm clueless)

Hi all, I’d just like a little help with saving the fact that an image is visible or not. What I’m trying to make is when a player “finds” a crystal by entering that crystals region3 area, I’ve got it so that the “Mystery” crystal image’s visibility to turn to false. Then the vacant space where the mystery image used to be to be is filled with the image of the crystal, by making the crystal image visible. I want this to save, so if the player leaves the game the “found” crystal images are all loaded in.

I know that I need to make a table and values of some description, but could I just have a little help on this one? I’m struggling to make it work.

Code:

if found == true then 
            --Make images visible
            if script.Parent.FoundClothing.Clothingframe.Scroll[v.Name].Visible == false then
                script.Parent.FoundClothing.Clothingframe.Scroll[v.Name].Visible = true
                local mystName = string.sub(v.Name, 1, (string.len(v.Name) - 5))
                script.Parent.FoundClothing.Clothingframe.Scroll[mystName].Visible = false
                --Turns visible off for mystery; play sound
                local congratsound = game.Workspace.SoundEffects.Congrats
                congratsound.Playing = true
                wait(2)
                congratsound.Playing = false

                break
            end
        end

Thanks.

1 Like

Here’s an example:

local SaveTable = {
	Item1 = {
		Visible = true
	},
	Item2 = {
		Visible = false
	}
}

local Ok, Result = pcall(function()
	return Key:GetAsync(PlayerKey)
end)
if Ok then
	YourStuff1.Visible = Result.Item1.Visible or DefaultValue -- true (DefaultValue in case it's nil)
	YourStuff2.Visible = Result.Item2.Visible or DefaultValue -- false (DefaultValue in case it's nil)
end

Result returns whatever you stored (if the player has any data saved, otherwise nil).
In this case, the table with our information.

You also need to save the data, here’s a guide for that part:

2 Likes

And, just one question: where would I put this table code in my script to make it work? Or would I put it in a different script?

You’ll need to access it in order to save it, in this case, a modulescript or having it inside the script itself should work just fine.

1 Like

Not sure if I did it right, because it doesn’t work -

	if found == true then 
			--Make images visible
			if script.Parent.FoundClothing.Clothingframe.Scroll[v.Name].Visible == false then
				script.Parent.FoundClothing.Clothingframe.Scroll[v.Name].Visible = true
				local mystName = string.sub(v.Name, 1, (string.len(v.Name) - 5))
				script.Parent.FoundClothing.Clothingframe.Scroll[mystName].Visible = false
				--Turns visible off for mystery; play sound
				-- Make table
				local SaveTable = {
					Item1 = {
						Visible = true
					},
					Item2 = {
						Visible = false
					}
				}

				local Ok, Result = pcall(function()
					return Key:GetAsync(PlayerKey)
				end)
				if Ok then
					mystName.Visible = Result.Item1.Visible or DefaultValue -- true (DefaultValue in case it's nil)
					v.Name.Visible = Result.Item2.Visible or DefaultValue -- false (DefaultValue in case it's nil)
				end
				local congratsound = game.Workspace.SoundEffects.Congrats
				congratsound:Play()
				wait(5)
				congratsound:Stop()

				break
			end
		end

Key would be the datastore you write to.
PlayerKey would be ex, their userid.
DefaultValue would be the default value if no data exists.


You also need a Players | Roblox Creator Documentation & Players | Roblox Creator Documentation event to indentify the player.
You should also save on an interval (ex, every 2-3 minutes), and use the DataModel | Roblox Creator Documentation function.

1 Like