data script (server script service)


local ds = game:GetService("DataStoreService"):GetDataStore("DayCareData")
local StatsToAdd = { 
	["City"] = false,
}


	local Prefix = plr.UserId

	local DataFolder = Instance.new("Folder", plr) 
	DataFolder.Name = "Portal" 
	print(plr.Name)
	
	
	for i,v in pairs(StatsToAdd) do 
		local NewInst = Instance.new("BoolValue", DataFolder) 
		NewInst.Name = i
		NewInst.Value = v
	end
	print("saving")

	local Data = nil
	pcall(function()
		Data = ds:GetAsync(Prefix)
	end)

	if Data ~= nil then
		for i,v in pairs(DataFolder:GetChildren()) do
			v.Value = Data[v.Name]
		end
	end
end)
print("saved almost")
game.Players.PlayerRemoving:Connect(function(plr)
	local Prefix = plr.UserId

	local DataFolder = plr.Portal
	print("saved in a while")
	pcall(function()
		if DataFolder then
			local SaveData = {}

			for i,v in pairs(DataFolder:GetChildren()) do
				SaveData[v.Name] = v.Value
			end

			ds:SetAsync(Prefix, SaveData)
		end
	end)
end)

print("saved")

~~~~~~~~~~~

~~~~~~
click to claim the portal (local script)

script.Parent.MouseButton1Click:Connect(function() script.Parent.Position = UDim2.new(8.225, 0,8.108, 0) game.ReplicatedStorage.Click:Play() wait(0.5) script.Parent.Position = UDim2.new(8.225, 0,7.978, 0)

if game.Players.LocalPlayer.leaderstats.Cash.Value > 1000 and game.Players.LocalPlayer.Portal.City.Value == false then
	game.Players.LocalPlayer.leaderstats.Cash.Value = game.Players.LocalPlayer.leaderstats.Cash.Value -1000
	game.Workspace.City.CityPart:Destroy()
	local DoorM = Folder:FindFirstChild("Door Model1")
	DoorM.Door.Position = Vector3.new(-724.184, 203.288, -310.016)
	game.Players.LocalPlayer.Portal.City.Value = true ------ here the value sets to true
elseif game.Players.LocalPlayer.leaderstats.Cash.Value > 1000 and game.Players.LocalPlayer.Portal.City.Value == true then
	script.Parent.Parent.Error.Text = "ERROR: YOU ALREADY OWN THIS MAP"
	script.Parent.Parent.Error.Visible = true
	game.ReplicatedStorage.error:Play()
	wait(1)
	script.Parent.Parent.Error.Visible = false
	
	elseif game.Players.LocalPlayer.leaderstats.Cash.Value < 1000 then
	script.Parent.Parent.Error.Visible = true
	game.ReplicatedStorage.error:Play()
	wait(1)
	script.Parent.Parent.Error.Visible = false
end

end)


3 comments

0

Is it printing anything?

0

yes

0

I put after the value goes to true and it tells me is set to false.