Hi. I have a simulator game and I want players to be able to buy areas, and the bought areas save. Here is my server script:

local ds = game:GetService("DataStoreService")
local gs = ds:GetDataStore("GrassyStore")
game.Players.PlayerAdded:Connect(function(plr)
	local f = Instance.new("Folder",plr)
	f.Name = "Pits"
	local g = Instance.new("BoolValue",f)
	g.Name = "OwnsGrassy"
	g.Value = gs:GetAsync(plr.UserId,g.Value) or false
	wait()
	if g.Value == true then
		game.ReplicatedStorage.RJFISJDIJWEF:FireClient(plr)
	end
end)
game.Players.PlayerRemoving:Connect(function(plr)
	gs:SetAsync(plr.UserId,plr.Pits.OwnsGrassy.Value)
end)

Here is the local script that should remove the door client side:

game.ReplicatedStorage.RJFISJDIJWEF.OnClientEvent:Connect(function()
	workspace.OwnGrassy:Destroy()
end)

And here is the local script where the player buys it.

local p = workspace:WaitForChild("OwnGrassy")
local g = p:WaitForChild("SurfaceGui")
local b = g:WaitForChild("TextButton")
b.MouseButton1Click:Connect(function()
	local plr = game.Players.LocalPlayer
	local l = plr:WaitForChild("Pits")
	local o = l:WaitForChild("OwnsGrassy")
	if plr.leaderstats.Points.Value >= 50 then
		plr.leaderstats.Points.Value = plr.leaderstats.Points.Value - 50
		p:Destroy()
		o.Value = true
	end
end)

Both of the local scripts are in StarterGui and the script is in Workspace. It successfully removes the door when bought, but does not when the value it true when the player enters the game.

3 comments

0

I think you should change the value server side. Because the change won't replicate to the server, so the server won't see it change and won't save the value.

0

I will try that thank you.

0

Thanks so much! It works fine now.