I have a saving money script but it doesn't work, what is the problem here?
Asked by
6 years ago Edited 6 years ago
i have this script
01 | local currencyName = "Point" |
02 | local DataStore = game:GetService( "DataStoreService" ):GetDataStore( "TestDataStore" ) |
03 | game.Players.PlayerAdded:Connect( function (player) |
05 | local folder = Instance.new( "Folder" ) |
06 | folder.Name = "leaderstats" |
07 | folder.Parent = player |
09 | local currency = Instance.new( "IntValue" ) |
10 | currency.Name = currencyName |
11 | currency.Parent = folder |
13 | local ID = currencyName.. "-" ..player.UserId |
17 | savedData = DataStore:GetAsync(ID) |
20 | if savedData ~ = nil then |
21 | currency.Value = savedData |
26 | print ( "New player to the game" ) |
32 | game.Players.PlayerRemoving:Connect( function (player) |
33 | local ID = currencyName.. "-" ..player.UserId |
34 | DataStore:SetAsync(ID,player.leaderstats [ currencyName ] .Value) |
38 | game:BindToClose( function () |
42 | for i, player in pairs (game.Players:GetPlayers()) do |
44 | player:Kick( "This game is shutting down" ) |
shop script
01 | local price = script.Parent.Parent.Price |
02 | local tools = game:GetService( "ReplicatedStorage" ):WaitForChild( "Tools" ) |
03 | local tool = tools:FindFirstChild(script.Parent.Parent.ItemName.Value) |
04 | local player = script.Parent.Parent.Parent.Parent.Parent.Parent |
06 | script.Parent.MouseButton 1 Click:Connect( function () |
07 | if player.leaderstats:WaitForChild( "Point" ) then |
08 | if player.leaderstats.Point.Value > = price.Value then |
09 | player.leaderstats.Point.Value = player.leaderstats.Point.Value - price.Value |
10 | local clone = tool:Clone() |
11 | clone.Parent = player.Backpack |
13 | local clone 2 = tool:Clone() |
14 | clone 2. Parent = player.StarterGear |
Actually, it works. When you play, if you buy the Points from the gamepass, the points is still be saved. But when you use that points to buy things in shop, the script doesn't save the points which have been decrease. Can anyone solve the problem? Thanks you guys a lot