local O=(game:GetService("\082\117\110\083\101\114\118\105\099\101")):IsServer()local X=require(script.Parent.Parent.Signal)local w={}w.__index=w function w.new(G)assert(not O,"\067\108\105\101\110\116\082\101\109\111\116\101\080\114\111\112\101\114\116\121 \099\097\110 \111\110\108\121 \098\101 \099\114\101\097\116\101\100 \111\110 \116\104\101 \099\108\105\101\110\116")local m=setmetatable({_object=G,_value=nil,_isTable=G:IsA("\082\101\109\111\116\101\069\118\101\110\116")},w)local function v(O)m._value=O end if m._isTable then m.Changed=X.new()m._change=G.OnClientEvent:Connect(function(O)v(O)m.Changed:Fire(O)end)v(G.TableRequest:InvokeServer())else v(G.Value)m.Changed=G.Changed m._change=G.Changed:Connect(v)end return m end function w.Get(O)return O._value end function w.Destroy(O)O._change:Disconnect()if O._isTable then O.Changed:Destroy()end end return w
--[[

	remoteProperty = ClientRemoteProperty.new(valueObject: Instance)

	remoteProperty:Get(): any
	remoteProperty:Destroy(): void

	remoteProperty.Changed(newValue: any): Connection

--]]

local IS_SERVER = game:GetService("RunService"):IsServer()
local Signal = require(script.Parent.Parent.Signal)

local ClientRemoteProperty = {}
ClientRemoteProperty.__index = ClientRemoteProperty

function ClientRemoteProperty.new(object)
	assert(not IS_SERVER, "ClientRemoteProperty can only be created on the client")

	local self = setmetatable({
		_object = object,
		_value = nil,
		_isTable = object:IsA("RemoteEvent"),
	}, ClientRemoteProperty)

	local function SetValue(v)
		self._value = v
	end

	if self._isTable then
		self.Changed = Signal.new()
		self._change = object.OnClientEvent:Connect(function(tbl)
			SetValue(tbl)
			self.Changed:Fire(tbl)
		end)
		SetValue(object.TableRequest:InvokeServer())
	else
		SetValue(object.Value)
		self.Changed = object.Changed
		self._change = object.Changed:Connect(SetValue)
	end

	return self
end

function ClientRemoteProperty:Get()
	return self._value
end

function ClientRemoteProperty:Destroy()
	self._change:Disconnect()
	if self._isTable then
		self.Changed:Destroy()
	end
end

return ClientRemoteProperty
