Hello everyone!
Why does the currency return to its original values after spending it, and it is not saved.
This is footages proofing my word’s:
This is script of buy button:
local tws = game:GetService("TweenService")
local i = TweenInfo.new(0.3,Enum.EasingStyle.Sine,Enum.EasingDirection.In)
local plr = game.Players.LocalPlayer
script.Parent.MouseEnter:Connect(function()
tws:Create(script.Parent,i,{Rotation = 10}):Play()
game.SoundService.SFX["Enter & Back"]:Play()
end)
script.Parent.MouseLeave:Connect(function()
tws:Create(script.Parent,i,{Rotation = 0}):Play()
end)
script.Parent.MouseButton1Click:Connect(function()
game.SoundService.SFX["Enter & Back"]:Play()
if plr.leaderstats["Fool's"].Value >= 100 or plr.leaderstats["Fool's"].Value == 100 then
plr.leaderstats.Multiplier.Value = plr.leaderstats.Multiplier.Value +1
plr.leaderstats["Fool's"].Value = plr.leaderstats["Fool's"].Value -100
end
end)
Script of leaderstats:
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder",plr)
leaderstats.Name = "leaderstats"
local coins1 = Instance.new("NumberValue",leaderstats)
coins1.Name = "Fool's"
local coins2 = Instance.new("NumberValue",leaderstats)
coins2.Name = "Multiplier"
end)
Script of datastore:
local data = game:GetService("DataStoreService"):GetDataStore("SaveData")
game.Players.PlayerAdded:Connect(function(plr)
wait()
local plrid = "id_"..plr.UserId
local save1 = plr.leaderstats["Fool's"]
local save2 = plr.leaderstats.Multiplier
local GetSaved = data:GetAsync(plrid)
if GetSaved then
save1.Value = GetSaved[1]
save2.Value = GetSaved[2]
else
local nfs = {save1.Value,save2.Value}
data:SetAsync(plrid,nfs)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
data:SetAsync("id_"..plr.UserId,{plr.leaderstats["Fool's"].Value,plr.leaderstats.Multiplier.Value})
end)
This is short topic and sorry for my grammar issues, my english is bad.