I am making a gui shop where you can buy weapons and gears with a currency called gems. When i want to buy a weapon and i press a "Buy" button, that button changes to an "Equip" button. My problem is i want to know how i can add a datastore to my script so that when i leave the game, the button still appears as an equip button only for me.
This is my line of code as a Local Script inside the buy button
local player = game.Players.LocalPlayer
local gems = player:WaitForChild('leaderstats').Gems
local buyButton = script.Parent
local equipButton = script.Parent.Equip
local errorMessage = script.Parent.Parent.Parent.Parent.Parent.ErrorMessage
local gemImage = script.Parent.Gem
script.Parent.MouseButton1Click:connect(function()
if gems.Value >= 50 and not player.Backpack:FindFirstChild('HyperlaserGun') and not player.StarterGear:FindFirstChild('HyperlaserGun') and not
player.Character:FindFirstChild('HyperlaserGun') then
game.Lighting.WeaponFolder.HyperlaserGun:Clone().Parent = player.Backpack
game.Lighting.WeaponFolder.HyperlaserGun:Clone().Parent = player.StarterGear
gems.Value = gems.Value - 50
equipButton.Visible = true
gemImage.Visible = false
else
if player.Backpack:FindFirstChild('HyperlaserGun') or player.StarterGear:FindFirstChild('HyperlaserGun') or player.Character:FindFirstChild('HyperlaserGun') then
errorMessage.Visible = true
errorMessage.Text = 'You already own this item!'
wait(1.5)
errorMessage.Visible = false
errorMessage.Text = "You don't have enough Gems to purchase this!"
else
errorMessage.Visible = true
wait(1.5)
errorMessage.Visible = false
end
end
end)

2 comments
you save the "Stats" not the "Gui"
Yes, you would save values when using data store. There is no such thing is "saving GUIs" because GUIs use values to present themselves.