Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I need help with my delete pet button, with the data store?

Me and my friend finished Alvin_Blox's pet system tutorial. He never taught how to make a delete pet button. After some time, me and my friend did a script.

In the delete button we did a LocalScript.

local player = game.Players.LocalPlayer
local petName = script.Parent.Parent.PetName
local PetInventory = player:WaitForChild("PetInventory")

script.Parent.MouseButton1Click:Connect(function()
	local weNeedToDeleteThis = PetInventory:FindFirstChild(petName.Text)
	weNeedToDeleteThis:Destroy()
	script.Parent.Parent:Destroy()
end)	

Player gets the player PetName gets the name of the pet PetInventory gets the player's pet inventory, where the pets are held in stringvalue weNeedToDeleteThis is what we need to delete

The script actually worked, we were very happy. Then I said "try the data, see if it saved." Nope. It does not save the delete... when we rejoined our pets were back.

If someone could teach how this could save -- that would be greatly appreciated.

Respond to this or DM ItzPolar_YT#5778 on Discord or DM @ItzPolarYT on Twitter.

Thanks, ItzPolar_YT (Sour Studios :D Owner, Object Simulator Developer)

1 comment

0

Use a script instead of a local script, and in the script you use to save the pets try adding a function to check whether or not something has happened to the pet

1 answer

Start here: https://developer.roblox.com/en-us/articles/Data-store

I personally used to hate datastore stuff but if you stick with it you'll wrap your head around it eventually :)

Make sure you're doing this stuff in a script (server script) rather than local script though unles oyu're gonna be using events... I'm not sure if its the proper way to do it but I tend to set up my datastore stuff in a module script so I can call to it easily and keep it all in a nice format :)

I'm not sure if the following is the best way of doing things, I put everything into one datastore and im not sure if thats right but.... Perhaps you could :GetAsync() for everyone that joins the game and put their data into a table (key as some form of ID like "Player_" .. player.UserId and value as their data). then their data could be a table of values for their cash etc. and another table (within the first table) for their per invintory. When you're trying to store tables on datastores you can use (https://developer.roblox.com/en-us/api-reference/function/HttpService/JSONEncode) HTTPService:JSONEncode(table) and HTTPService:JSONDecode(table) to switch between a useful editabled table and a string for storage :)

When you want to delete a pet get their pet invintory table, decode it, delete the pet data, encode it, send it to be saved.

This discussion is preserved as it was. New answers, comments, and votes are closed.