I was making candy to cash shop and I’ve run into this issue where it doesn’t save the new cash and candy values. I have a working data store that saves these values when you get them from elsewhere but when it comes down to this candy to cash shop, it doesn’t save. I was maybe thinking it has something to do with the script I made for the shop?
Shop:
local button = script.Parent
local player = game.Players.LocalPlayer
local playerstats = player:WaitForChild("leaderstats")
local CandyStats = playerstats:WaitForChild("Candies")
local CashStats = playerstats:WaitForChild("Cash")
local TextBox = script.Parent.Parent.CandyInput
local Successsound = script.Parent.Parent.Parent.Sounds.Success
local FailSound = script.Parent.Parent.Parent.Sounds.Fail
TextBox:GetPropertyChangedSignal("Text"):Connect(function()
TextBox.Text = TextBox.Text:gsub('%D+', '');
end)
button.MouseButton1Click:Connect(function(plr)
if (tonumber(TextBox.Text)) > CandyStats.Value then
FailSound:Play()
button.BackgroundColor3 = Color3.new(1, 0, 0)
button.Text = ""
button.Text = "Insufficient Candies!"
else
local inputedamount = tonumber(TextBox.Text)
Successsound:Play()
button.BackgroundColor3 = Color3.new(0, 1, 0)
button.Text = "Sold!"
TextBox.Text = ""
CashStats.Value = CashStats.Value + inputedamount
CandyStats.Value = CandyStats.Value - inputedamount
end
end)
Data Store:
local DS = game:GetService("DataStoreService")
local SaveData = DS:GetDataStore("SaveData")
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local Candies = Instance.new("IntValue")
Candies.Name = "Candies"
Candies.Parent = leaderstats
local Cash = Instance.new("IntValue")
Cash.Name = "Cash"
Cash.Parent = leaderstats
local plrkey = "id_"..plr.userId
local CandiesSave = plr.leaderstats.Candies
local CashSave = plr.leaderstats.Cash
local GetSaved = SaveData:GetAsync(plrkey)
if GetSaved then
CandiesSave.Value = GetSaved[1]
CashSave.Value = GetSaved[2]
else
local NumberForSaving = {CandiesSave.Value, CashSave.Value}
DS:GetAsync(plrkey, NumberForSaving)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
SaveData:SetAsync("id_"..plr.userId, {plr.leaderstats.Candies.Value, plr.leaderstats.Cash.Value})
end)
This is my first Devforum post so if I did something wrong or something weird please tell me