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

How would I go about making scripts that will save a car once purchased?

Asked by 5 years ago
Edited 5 years ago

Hello everyone I have a leaderboard cash saving script that works perfect. But I don't know how I can save the cars when they're purchased. I have the car purchase scripted so I don't need help with that. If you guys can send links or ideas. A push in the right direction is all I need.

2 answers

Log in to vote
0
Answered by 5 years ago

Hi week,

I would recommend adding a String Value inside a folder inside the Player every time a car is purchased. This folder will have many StringValues under it which have the Value of the name of the car.

So, when the player is leaving you just need to loop through these StringValues and save their Values using :SetAsync(). Then when a player is joining back, you just get those Values using :GetAsync() and loop through all of the values and create a StringValue for each under that folder that is supposed to house all of the StringValues.

I hope I helped and I know this is possible because I've made this system before with a Pokemon data storage, and it worked.

Thanks,

Best regards,

~~ KingLoneCat

Ad
Log in to vote
0
Answered by 5 years ago

So this is sort of tricky, considering Datastores are mainly used for Leaderstats. What you can do, is set a BoolValue inside of the car, and when the player buys it, set the bool value to True. Then make a datastore FOR the boolvalue, and finally make a script that checks when a player joins if the Bool is set to true, and if it is, then give the player the car. So just add a bool into the car, in the car giving script add a line that sets the bool to true when bought, add a datastore for the bool (Made one for you, look below) and make a script that checks if a player has bool when they join the game. (Also made one for you)

Put both these inside ServerScript's in ServerScriptService

Bool-Datastore script:

local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("CoinSaveSystem")

game.Players.PlayerAdded:Connect(function(plr)
    local Bool = --Set this variable to wherever the BoolValue is located

    Bool.Value = ds1:GetAsync(plr.UserId) or false
    ds1:SetAsync(plr.UserId, Bool.Value)

    Bool.Changed:Connect(function()
        ds2:SetAsync(plr.UserId, Bool.Value)
    end)
end)

CarChecker script:

game.Players.PlayerAdded:Connect(function(player)
local Bool = --Set to location of Bool
if Bool.Value == true then
--Add Code Here to Give the Players the car
else
print("Player didn't already own car")
end
end)

Feel Free to report any errors or questions

0
I'll use your answer and KingLoneCat answer. This can help me too I'm sure! User#23407 5 — 5y

Answer this question