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
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:
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