Part visible for specific players and how to save properties?

Hello, scripters!
I am creating a simulator and I want to make a ‘Buy Area’ shop. However, When I do
if bought == true then part.Transparency = 1 part.CanCollide = false end
it does work but everyone can no longer see the part and can go through it. I also tried using ‘:Destroy()’ but it does the same thing. Also how could I save the part’s properties?
Regards, Flash!

1 Like

If you want it only to happen on a specific player’s screen, use a local script.

1 Like

Ok I will check that and then I will be back.

Ok thanks. It works now. When I buy the area, it takes the required money off and makes it invisible for the other players. But do you have any ideas on how to save those properties?

You mean save once the player has left?

1 Like

Yes that is what I mean. charssss

I know it is using DataStoreService but how do I specifically save the two properties CanCollide and Transparency for the player.

I only know how to save leaderstats

If you know how to save leaderstats then you should know how to save anything in general, but:

local DataStoreService = game:GetService("DataStoreService")
local PropertiesStore = DataStoreService:GetDataStore("Properties")


PropertiesStore:SetAsync(player.UserId.. "CanCollide", true/false) -- Saving
PropertiesStore:SetAsync(player.UserId.. "Transparency", 1) -- Saving

Also, when saving / retrieving data you typically want to do it in a pcall function, but this is just an example

Ok I don’t really understand what ur saying

Don’ t I have to Get Async first I am confused.

Get Async will retrieve data, and Set Async saves data

PropertiesStore:GetAsync(player.UserId.. "CanCollide") -- Will return the value, in this case true
PropertiesStore:SetAsync(player.UserId.. "CanCollide", true) -- Saves the value

Ok so does it have to be:

local dss = game:GetService("DataStoreService")
local MyDss = dss:GetDataStore("PropertiesStore")

game.Players.PlayerAdded:Connect(function(plr)
   MyDss:SetAsync(plr.UserId.. "CanCollide", true/false)
   MyDss:SetAsync(plr.UserId.. "Transparency", 1)
end)

Well, that would save whenever a player joins the server, so it probably doesn’t do much. Also, instead of doing true/false do either true or false, whichever you want it to be.

You also probably want to retrieve the data whenever a player joins, and save the data when the player leaves (or at any other time)

local DataStoreService = game:GetService("DataStoreService")
local MyDataStore = DataStoreService:GetDataStore("Properties")


game.Players.PlayerAdded:Connect(function(player)
   local collideable = MyDataStore:GetAsync(player.UserId.. "CanCollide")
end)

game.Players.PlayerRemoving:Connect(function(player)
   MyDataStore:SetAsync(player.UserId.. "CanCollide", PlayerCanCollide)
end)

Set PlayerCanCollide to whatever the value actually is when the player is leaving the game

How does the script know what CanCollide is then? Does it just look through the game? :
MyDataStore:GetAsync(player.UserId… “CanCollide”)

In the GetAsync line, player.UserId.. "CanCollide" is just the key, the variable collideable would be the value for CanCollide (either true or false)

1 Like

So basically, would I have to do:

local collidable = part.CanCollide.Value

No wait. I am still confused. You defined it in DataStore script

Yes, but the other way around. part.CanCollide = collideable

Oh alright thanks charssssssssssss