How would I go about making a part destroyed save datastore

So I have a question how would I go about making an area buy so if you click this part with a clickdectator its gone out of the game forever and if you rejoin you won’t be able to see that buy part again. (Just to clarify this shouldn’t show for everyone in a game just the local player who bought the area.)

So how I would go about this if I understand correctly it would be to detect the click detector locally and when it is bought the part is deleted locally so that the local plr cannot see it but everyone else still can, then I would send a request to the server to set some sort of variable that says the plr has bought this door and save it in a data store. On the server-side, I would put as the plr is added it would get all the door-bought data and go through all the doors to see if it was bought or not. if it was then send a request to the client to delete the door.

1 Like

Firstly, create the boolvalue inside replicatedstorage, called: “Destroyed”

Here is code, you need to use:

Script, put it inside click detector.

script.Parent.MouseClick:Connect(function()
     local part = -- here your area
     part:Destroy()
     game.ReplicatedStorage.Destroyed.Value = true
end)

Also script, put it inside ServerScriptService:

game.Players.PlayerAdded:Connect(function(player)
     local ds = game:GetService("DataStoreService") -- Getting dataservice
     local data = ds:GetDataStore("Destroyed") -- Getting our data
     local value = game.ReplicatedStorage.Destroyed -- Your value
     local key = "Key-".. player.UserId -- Secret data key
     if not data:GetAsync(key) then
           data:SetAsync(key, false)
     else
           value.Value = data:GetAsync(key)
     end
end)

game.Players.PlayerRemoving:Connect(function(player)
     local ds = game:GetService("DataStoreService") -- Getting dataservice
     local data = ds:GetDataStore("Destroyed") -- Getting our data
     local value = game.ReplicatedStorage.Destroyed -- Your value
     local key = "Key-".. player.UserId -- Secret data key

     data:SetAsync(key, value.Value)
end)

It should working, if no- idk

this will not work due to replicated storage being public to client and server

Logical is correct and also if I didn’t explain correct I am trying to get it so that it doesn’t destroy the part for everyone it just destroys the part for the player who clicked the clickdetector.

Can you explain more what you mean here?

What I mean is, @MrGameboy123456789 is trying to only show or in this case remove a part from the client, if you were to do what @eboy_pro123 had suggested then everyone’s parts would be destroyed because replicated storage is not local the server can see it meaning anything that happens in replicated storage can be seen from all clients in that server. so @eboy_pro123 would not work for what @MrGameboy123456789 is trying to do.

If you need more help just msg me