I am currently having an issue with my game development. I added datasave for gui, so when you buy something (like a weapon), you can buy it only once because when you rejoin the game the button saves and says that you already have that weapon.
local ds = dds:GetDataStore(“datastorecallthiswhatever”)
game.Players.PlayerAdded:Connect(function(player)
local saveValue1 = player:WaitForChild("PlayerGui"):WaitForChild("ScreenGui"):WaitForChild("Shop"):WaitForChild("primaspecifica"):WaitForChild("TextButton").bought
print("working")
local data
local success, errormessage = pcall(function()
data = ds:GetAsync(player.UserId)
end)
if success then
print("loading")
saveValue1.Value = data
else
print("Error whilst trying to save data!")
warn(errormessage)
end
if saveValue1.Value == 1 then
print(player.Name,"owns sword")
saveValue1.Parent.Text = "Owned"
saveValue1.Parent.BackgroundColor3 = Color3.new(227, 211, 28)
saveValue1.Parent.Main:Destroy()
saveValue1.Parent.LocalScript:Destroy()
end
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
ds:SetAsync(player.UserId, saveValue1.Value)
end)
if success then
print("Saved!")
else
print("Error whilst trying to save data!")
warn(errormessage)
end
end)
end)
But if you reset or get killed the data save resets and you need to buy the weapon again.
The gui is probably detecting if your “Owner” 's Value is true, if its true its gonna keep it owned, or if false its not gonna be owned, so you probably should stop saving the Owner’s value if you want to buy that item more times, If you want to buy it more times you should make a Int Value that saves the amount of swords you bought.
Also if you want to reset “Owned” value when you reset or get killed, you can simply detect if the player 's character died and set the Owned value to false.
(Make it on a server-sided script on ServerScriptService)