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

How do I make sure the purchased tool stays within the player's inventory after death?

Asked by 5 years ago
Edited 5 years ago

In my previous question, I asked on how I would make sure a tool will always remain in the player's inventory even after death.

The solution someone gave me was to use :WaitForChild('StarterGear').

This is my shop script, which is a LocalScript in an ImageButton.

01script.Parent.MouseEnter:Connect(function()
02    game.StarterPlayer.Mouse_hover:Play()
03end)
04 
05local canPurchase = false
06 
07script.Parent.MouseButton1Click:Connect(function()
08    game.StarterPlayer.Select:Play()
09    local confirmPurchase = script.Parent.Parent.Parent.ConfirmPurchase:Clone()
10    confirmPurchase.Visible = true
11    confirmPurchase.Parent = script.Parent.Parent.Parent
12    confirmPurchase.Yes.MouseButton1Click:Connect(function()
13        canPurchase = true
14        if game.Players.LocalPlayer:WaitForChild('leaderstats').Vertigo.Value >= 25000 then
15            game.StarterPlayer.SFX_SelectAvailable:Play()
View all 28 lines...

Terribly sorry if it's hard to read, it's the formatting.

Can anyone help me fix this issue? I've had it for a very long time.

Regards, Sensei.

2 answers

Log in to vote
1
Answered by
Benbebop 1049 Moderation Voter
5 years ago

I would personally use DataStores for this. DataStores are tables that persist between sessions. To insert/modify data in a DataStore array you must use SetAsync, UpdateAsync and RemoveAsync.

SetAsync creates a new value and modifies it to the parameters specified.

Ex.

1local DataStoreService = game:GetService("DataStoreService")
2local ExampleStore = DataStoreService:GetDataStore("ExampleData")
3 
4ExampleStore:SetAsync("ExamplePlayer", 50)

This creates a new value ExamplePlayer and sets it's corresponding value to 50.

UpdateAsync modifies an existing value to the parameters specified.

Ex.

1local DataStoreService = game:GetService("DataStoreService")
2local ExampleStore = DataStoreService:GetDataStore("ExampleData")
3 
4ExampleStore:UpdateAsync("ExamplePlayer", 50)

This changes ExamplePlayer's corresponding value to 50

RemoveAsync removes a value in the array.

Ex.

1local DataStoreService = game:GetService("DataStoreService")
2local ExampleStore = DataStoreService:GetDataStore("ExampleData")
3 
4ExampleStore:RemoveAsync("ExamplePlayer")

This removes ExamplePlayer and its corresponding value

For more see Data Stores.

0
Instead of saving numbers, bools and stings, is it possible to save objects by simply putting in ExampleStore:SetAsync("Player",object)? Sensei_Developer 298 — 5y
0
No, since an ObjectValue just stores a link of sorts to an object and objects are not persistent between sessions. Even though you aren’t exactly storing between sessions DataStores are designed to. Benbebop 1049 — 5y
Ad
Log in to vote
-3
Answered by 5 years ago
Edited 5 years ago

Just pop this in ServerScriptService

001--[[
002 
003MAde by Bssiemeow!
004--]]
005 
006local rs = game:GetService("ReplicatedStorage")
007local ds = game:GetService("DataStoreService")
008local store = ds:GetDataStore("saveStore")
009local library = rs:WaitForChild("Library")
010 
011--< directory functions
012 
013local dir = {}
014 
015local function edit(player, list)
View all 125 lines...
0
I know where this script came from, buddy. Why are you copy pasting? Down voted. Sensei_Developer 298 — 5y
0
^^^ also, why are you plagiarizing? You wrote your own name as credit... This belongs to Shiro75. Sensei_Developer 298 — 5y
0
it doesn't so why are you harrasing me?!? Bssiemeow 30 — 5y

Answer this question