local L=(game:GetService("\082\117\110\083\101\114\118\105\099\101")):IsServer()local A=require(script.Parent.Parent.Signal)local g={}g.__index=g function g.new(E)assert(not L,"\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=E,_value=nil;_isTable=E:IsA("\082\101\109\111\116\101\069\118\101\110\116")},g)local function r(L)m._value=L end if m._isTable then m.Changed=A.new()m._change=E.OnClientEvent:Connect(function(L)r(L)m.Changed:Fire(L)end)r(E.TableRequest:InvokeServer())else r(E.Value)m.Changed=E.Changed m._change=E.Changed:Connect(r)end return m end function g.Get(L)return L._value end function g.Destroy(L)L._change:Disconnect()if L._isTable then L.Changed:Destroy()end end return g
--[[

	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
