Hi so I’ve maked an shop that is saving. I don’t know why but my script to buy doesn’t work, any help?
Shop Script That change the money collected per coin
game.Workspace["MAP 1"].Shop.Circle.Attachment.ProximityPrompt.Triggered:Connect(function()
local TweenService = game:GetService("TweenService")
script.Parent.Parent.Enabled = true
TweenService:Create(game.Lighting.Blur, TweenInfo.new(0.3), {Size = 24})
workspace["MAP 1"].Shop.Circle.Attachment.ProximityPrompt.Enabled = false
end)
script.Parent.Frame["1Multiplicator"].Upgrade.Button.MouseButton1Click:Connect(function()
local leaderstats = game.Players.LocalPlayer.leaderstats
if leaderstats.Multiplier.Value == 0 then
if leaderstats["Coins 💰"].Value >= 50 then
leaderstats.Multiplier.Value = 1
game.ReplicatedStorage.MoneyPerCoin.Value = 2
leaderstats["Coins 💰"].Value -= 50
script.Parent.Frame["1Multiplicator"].Bar.UIGradient.Offset = Vector2.new(0.1, 0)
script.Parent.Frame["1Multiplicator"].Label = "Coins Multiplicator (x2)"
end
end
if leaderstats.Multiplier.Value == 1 then
if leaderstats["Coins 💰"].Value >= 250 then
leaderstats.Multiplier.Value = 2
game.ReplicatedStorage.MoneyPerCoin.Value = 3
leaderstats["Coins 💰"].Value -= 250
script.Parent.Frame["1Multiplicator"].Bar.UIGradient.Offset = Vector2.new(0.2, 0)
script.Parent.Frame["1Multiplicator"].Label = "Coins Multiplicator (x3)"
end
end
if leaderstats.Multiplier.Value == 2 then
if leaderstats["Coins 💰"].Value >= 500 then
leaderstats.Multiplier.Value = 3
game.ReplicatedStorage.MoneyPerCoin.Value = 4
leaderstats["Coins 💰"].Value -= 500
script.Parent.Frame["1Multiplicator"].Bar.UIGradient.Offset = Vector2.new(0.2, 0)
script.Parent.Frame["1Multiplicator"].Label = "Coins Multiplicator (x4)"
end
end
end)
Datastore Creation Script
local DataStoreService = game:GetService("DataStoreService")
local MyDataStore = DataStoreService:GetDataStore("MyDataStore")
-- # COINS # --
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local currency = Instance.new("IntValue")
currency.Name = "Coins 💰"
currency.Parent = leaderstats
local data
local succes, errormsg = pcall(function()
data = MyDataStore:GetAsync(player.UserId .. "-Coins")
end)
if succes then
currency.Value = data
end
------------------
local currency2 = Instance.new("IntValue")
currency2.Name = "Multiplier"
currency2.Parent = leaderstats
local data2
local succes2, errormsg2 = pcall(function()
data2 = MyDataStore:GetAsync(player.UserId .. "-Multiplier")
end)
if succes2 then
currency2.Value = data2
end
------------------
local currency3 = Instance.new("IntValue")
currency3.Name = "Zone"
currency3.Parent = leaderstats
local data3
local succes3, errormsg3 = pcall(function()
data3 = MyDataStore:GetAsync(player.UserId .. "-Zone")
end)
if succes3 then
currency3.Value = data3
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local succes, errormsg = pcall(function()
MyDataStore:SetAsync(player.UserId .. "-Coins", player.leaderstats["Coins 💰"].Value)
end)
if succes then
print("Succesfully saved data.")
end
------------------
local succes2, errormsg2 = pcall(function()
MyDataStore:SetAsync(player.UserId .. "-Multiplier", player.leaderstats["Multiplier"].Value)
end)
if succes2 then
print("Succesfully saved data.")
end
------------------
local succes3, errormsg3 = pcall(function()
MyDataStore:SetAsync(player.UserId .. "-Zone", player.leaderstats["Zone"].Value)
end)
if succes3 then
print("Succesfully saved data.")
end
end)
-- # Multiplier # --