Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does my script only save the leader stats and dosent save the vehicles purchased?

Asked by 4 years ago

Alright so i asked this question already about a month ago i did get an answer but it didnt seem to fix the problem so here it is. So basicly its a Datastore script thats meant to save the player`s cash and the vehicles that the player has purchased but it only saves the cash value but it dosent save the cars purchased, could someone help?

Script:

local DataStore = game:GetService("DataStoreService")
local ds1 = DataStore:GetDataStore("im not showing this")
local success, err = pcall(function()


game.Players.PlayerAdded:connect(function(player)
    local leader = Instance.new("Folder", player)
    leader.Name = "leaderstats"

    local Cash = Instance.new("IntValue", leader)
    Cash.Name = "Cash"

    Cash.Value = ds1:GetAsync(player.UserId) or 0
    ds1:SetAsync(player.UserId, Cash.Value)

    ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Zilko_Natalia.Purchased.Value, player.UserId.."Purchased_Zilko_Natalia")
        ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Voyage_D.Purchased.Value, player.UserId.."Purchased_Voyage_D")
        ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.DA_Ferra.Purchased.Value, player.UserId.."Purchased_DA_Ferra")
        ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.DA_Venerra.Purchased.Value, player.UserId.."Purchased_DA_Venerra")
        ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Hektor_Mediona.Purchased.Value, player.UserId.."Purchased_Hektor_Mediona")
        ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Mounts_Rake.Purchased.Value, player.UserId.."Purchased_Mounts_Rake")
        ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Novena_Acesera.Purchased.Value, player.UserId.."Purchased_Novena_Acesera")
        ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Roland_Motors_GTR.Purchased.Value, player.UserId.."Purchased_Roland_Motors_GTR")
        ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Surge_Maple_R.Purchased.Value, player.UserId.."Purchased_Surge_Maple_R")
        ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Voyage_Jalanster_Betamobili.Purchased.Value, player.UserId.."Purchased_Voyage_Jalanster_Betamobili")
        ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Voyage_Pengangkuter_30_CWT.Purchased.Value, player.UserId.."Purchased_Voyage_Pengangkuter_30_CWT")
        ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.DA_Ferra_F8_RT_Edition.Purchased.Value, player.UserId.."Purchased_DA_Ferra_F8_RT_Edition")
    wait(5)
    --Cash.Changed:connect(function()
        print("SavingData")
        ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Zilko_Natalia.Purchased.Value)
ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Voyage_D.Purchased.Value)
ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.DA_Ferra.Purchased.Value)
ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.DA_Venerra.Purchased.Value)
ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Hektor_Mediona.Purchased.Value)
ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Mounts_Rake.Purchased.Value)
ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Novena_Acesera.Purchased.Value)
ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Roland_Motors_GTR.Purchased.Value)
ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Surge_Maple_R.Purchased.Value)
ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Voyage_Jalanster_Betamobili.Purchased.Value)
ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Voyage_Pengangkuter_30_CWT.Purchased.Value)

        ds1:SetAsync(player.UserId, Cash.Value)
    end)

--end)

game.Players.PlayerRemoving:connect(function(player)

    local SavedData = Instance.new("BindableEvent")
    ds1:setAsync(player.UserId, player.leaderstats.Cash.Value)

    ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Zilko_Natalia.Purchased.Value)
ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Voyage_D.Purchased.Value)
ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.DA_Ferra.Purchased.Value)
ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.DA_Venerra.Purchased.Value)
ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Hektor_Mediona.Purchased.Value)
ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Mounts_Rake.Purchased.Value)
ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Novena_Acesera.Purchased.Value)
ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Roland_Motors_GTR.Purchased.Value)
ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Surge_Maple_R.Purchased.Value)
ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Voyage_Jalanster_Betamobili.Purchased.Value)
ds1:SetAsync(game.StarterGui.PurchaseGUI.Frame.Voyage_Pengangkuter_30_CWT.Purchased.Value)

    SavedData:Fire()

game:BindToClose(function()
    SavedData.Event:Wait()
end)
end)
end)
0
change game.StarterGui.PurchaseGui to player.PlayerGui.PurchaseGui Gameplayer365247v2 1055 — 4y
0
i replaced all but it didnt work. DaggerSaber 14 — 4y
0
You would want to create a folder instead of a value. Insert The Cars Purchased Into The Folder Then Save The Folder For The Player. Easier Said Than Done, but it can be done Mawfix 15 — 4y
0
Is that the only way to do it? Because that will take hours to replace every line in all of the scripts which has the Value in it. DaggerSaber 14 — 4y
View all comments (3 more)
0
It is Not The Only Was To Save them, but it is the best way in my opinion. If You want me to post a comment and be more in depth with it than tell me Mawfix 15 — 4y
0
yes i would like to see you go more in depth with this. DaggerSaber 14 — 4y
0
ok i did DaggerSaber 14 — 4y

1 answer

Log in to vote
0
Answered by
Mawfix 15
4 years ago

So You cannot save a model or type of physical thing as a value. Theoretically, you could but that would be a lot of unnecessary scripting. To-Do what you are asking you might want to put the Cars/Something you are saving Into the ServerStorage Service. Therefore you can start the process.

You Should clone the cars in ServerStorage, for example:

game.ServerStorage.Car1:Clone().Parent = player -- Put the player name or how parameter

This would work, but its best to keep it organized so doing this would be better

game.ServerStorage.CarFolder.Car1:Clone().Parent = player

There we go inside the folder to grab the car. This will make using Datastores a lot easier when you start to insert them into the DataStoreServiceFolder.

After you need to Clone the cars into the folder that is in leader stats and the player. Note You do not need to get rid of the Cash value in the leaderstats

You need to save the folder that is in the player to a Datastore so you can receive it later on the line. Next, you need to put the folder in the player like you would a cash datastore.

You would run an if statement on your game to check and see when a player wants to spawn a car. If they have the car in their folder then your car spawner will do its job

If this helped explain this please accept it as an answer

0
thank you for the answer i will try to do this and i will tell you if it worked DaggerSaber 14 — 4y
0
also i already have the cars folder in ServerStorage. So does that mean that i only have to make a folder in the player that would determine what cars the player owns like if the player owns a car it would get added to it? DaggerSaber 14 — 4y
0
What cars the player owns would be saved in the folder inside the player. Then run a if statement on let's say a spawn button that asks if the car they are spawning is in there folder and if it is it would spawn it for free. So yes Mawfix 15 — 4y
Ad

Answer this question