Issues with self.SelectingUnit

  1. What do you want to achieve? For it to set self.SelectingUnit

  2. What is the issue? For some reason It won’t set or get “self.SelectingUnit”

  3. What solutions have you tried so far? Everything.

local HttpService = game:GetService("HttpService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local getUnits = Remotes:WaitForChild("getUnits")
local updateInventoryEvent = Remotes:WaitForChild("UpdateInventory")

local UnitsMain = {}
UnitsMain.Priority = 1
UnitsMain.server = {}
UnitsMain.client = {}
UnitsMain.shared = {}

local UnitDatabase
local SummonService
local UnitRarities
local UnitStatsUtility
local UnitStatsConfig
local UnitTraits
local GlobalFunctions

function UnitsMain:Init(files)
	UnitDatabase = files["UnitDatabase"]
	SummonService = files["SummonService"]
	UnitRarities = files["UnitRarities"]
	UnitStatsUtility = files["UnitStats"]
	UnitStatsConfig = files["UnitStatsConfig"]
	UnitTraits = files["UnitTraits"]
	GlobalFunctions = files["GlobalFunctions"]

	if game:GetService("RunService"):IsClient() then
		UnitsMain.client:Init(files)
	end
end

function UnitsMain:Start(files)
	if game:GetService("RunService"):IsClient() then
		UnitsMain.client:Start(files)
	end
end

function UnitsMain.client:Init(files)
	local UnitRarities = files["UnitRarities"]
	local UnitDatabase = files["UnitDatabase"]
	local UnitLevels = files["UnitLevels"]
	local UnitStats = files["UnitStats"]
	local UnitTraits = files["UnitTraits"]
	local FormatNumbers = files["FormatNumbers"]
	local UnitGradient = files["UnitGradient"]
	local UnitHover = files["UnitHover"]
	

	local LOCAL_PLAYER = game:GetService("Players").LocalPlayer
	repeat task.wait() until LOCAL_PLAYER:GetAttribute("PlayerLoaded") == true
	repeat task.wait() until LOCAL_PLAYER:GetAttribute("DataLoaded") == true
	
	local UnitTemplate = ReplicatedStorage.Assets.Interface.UnitTemplates.Templates.UnitTemplate

	self.SelectingUnit = nil

	local function updateInfoPanel(unitData)
		if not unitData then
			UnitInfoHolder.Visible = false
			return
		end

		local definition = UnitDatabase.Units[unitData.Template]
		local rarityConfig = UnitRarities[unitData.Rarity] or UnitRarities["Unused Slot"]

		UnitInfoHolder.Visible = true
		UnitInfoHolder.UIGradient.Color = rarityConfig.Gradient.Color
		UnitInfoHolder.Texture.UIGradient.Color = rarityConfig.Gradient.Color
		
		UnitInfoName.Text = unitData.Name or unitData.Template
		
		UnitInfoRarity.UnitRarity.Text = unitData.Rarity
		UnitInfoRarity.UnitRarity.Gradient.Color = rarityConfig.Gradient.Color
		UnitInfoRarity.UIStroke.Gradient.Color = rarityConfig.Gradient.Color
		
		UnitGradient.animateGradient(UnitInfoRarity.UnitRarity.Gradient, "SpinAnim")
		UnitGradient.animateGradient(UnitInfoRarity.UIStroke.Gradient, "SpinAnim")
		
		local equipped, slotIndex = (function()
			for _, slot in ipairs(LOCAL_PLAYER.Hotbar:GetChildren()) do
				if slot.Value == unitData.UUID then
					return true, slot.Name
				end
			end
			return false, nil
		end)()
		
		if equipped then
			UnitInfoButtons.Equip.Label.Text = "Unequip"
			UnitInfoButtons.Equip.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
			UnitInfoButtons.Equip.Inner.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
		end
		
		if self.SelectingUnit then
			UnitInfoButtons.Equip.Label.Text = "Equip"
			UnitInfoButtons.Equip.BackgroundColor3 = Color3.fromRGB(20, 255, 55)
			UnitInfoButtons.Equip.Inner.BackgroundColor3 = Color3.fromRGB(20, 255, 55)
		end
		
		if InfoPanelConnections[UnitInfoButtons.Equip] then
			pcall(function() InfoPanelConnections[UnitInfoButtons.Equip]:Disconnect() end)
		end
		
		if InfoPanelConnections[UnitInfoButtons.Delete] then
			pcall(function() InfoPanelConnections[UnitInfoButtons.Delete]:Disconnect() end)
		end
		
		InfoPanelConnections[UnitInfoButtons.Delete] = UnitInfoButtons.Delete.Button.MouseButton1Click:Connect(function()
			Remotes.DeleteUnit:FireServer(unitData.UUID)
		end)
		
		InfoPanelConnections[UnitInfoButtons.Equip] = UnitInfoButtons.Equip.Button.MouseButton1Click:Connect(function()
			print(self.SelectingUnit)
			if self.SelectingUnit then
				Remotes.SelectingUnit:Fire(self.SelectingUnit, unitData)
				UnitInfoHolder.Visible = false
				self.SelectingUnit = nil
			else
				Remotes.UnEquipUnit:FireServer(unitData.UUID)
			end
		end)
		
		--renderUnitInViewport(UnitInfoViewport, unitData, definition, {0, 2.7, -1}, true)
	end

	local function createOrGetSlot(uuid, unitData)
		local slotInfo = InventorySlots[uuid]
		if slotInfo and slotInfo.Frame and slotInfo.Frame.Parent then
			slotInfo.unitData = unitData
			return slotInfo
		end

		local slotButton = UnitTemplate:Clone()
		slotButton.Name = uuid
		slotButton.Visible = true
		slotButton.Parent = UnitsInventory

		slotButton:SetAttribute("UUID", uuid)
		slotButton:SetAttribute("isHotbar", false)

		local slotConns = {}
		local function store(c)
			table.insert(slotConns, c)
		end

		store(slotButton.Button.MouseButton1Click:Connect(function()
			if LOCAL_PLAYER.SelectedUnit.Value == uuid then
				LOCAL_PLAYER.SelectedUnit.Value = ""
				updateInfoPanel(nil)
			else
				LOCAL_PLAYER.SelectedUnit.Value = uuid
				LOCAL_PLAYER.SelectedSlot.Value = 0
				updateInfoPanel(unitData)
			end
		end))

		UnitHover:registerUnit(slotButton, function() return unitData end, false, LOCAL_PLAYER)

		local slot = {
			Frame = slotButton,
			conns = slotConns,
			unitData = unitData,
		}

		InventorySlots[uuid] = slot
		return slot
	end

	local function destroySlot(uuid)
		local info = InventorySlots[uuid]
		if not info then return end

		for _, c in ipairs(info.conns or {}) do
			if c and c.Connected then pcall(function() c:Disconnect() end) end
		end

		local UnitImage = info.Frame:FindFirstChild("Holder"):FindFirstChild("Main"):FindFirstChild("UnitImage")
		if UnitImage and UnitImage.ViewportFrame then
			unloadViewport(UnitImage.ViewportFrame)
		end

		pcall(function() info.Frame:Destroy() end)
		InventorySlots[uuid] = nil
	end
	

	local function patchInventory(unitDataMap)
		for uuid, _ in pairs(previousUnitDataMap) do
			if not unitDataMap[uuid] and InventorySlots[uuid] then
				destroySlot(uuid)
			end
		end

		for uuid, unitData in pairs(unitDataMap) do
			local slot = InventorySlots[uuid]
			local dataChanged = not slot or slot.unitData ~= unitData

			if not slot then
				slot = createOrGetSlot(uuid, unitData)
			else
				slot.unitData = unitData
			end

			slot.Frame.Visible = passesSearch(unitData)
			if not dataChanged then continue end  -- skip visual updates if nothing changed

			local slotButton = slot.Frame
			local Glow = slotButton.Glow
			local ViewportFrame = slotButton.Holder.Main.UnitImage.ViewportFrame
			local LevelFrame = slotButton.Holder.Main.LevelFrame
			local Level = LevelFrame.Level
			local Stars = slotButton.Holder.Main.Stars
			local UnitName = slotButton.Holder.Main.UnitName
			local TraitImage = slotButton.Holder.Main.TraitIcon
			local Holder = slotButton.Holder
			local Main = Holder.Main

			local RarityConfig = UnitRarities[unitData.Rarity] or UnitRarities["Unused Slot"]
			local UnitDefinition = UnitDatabase.Units[unitData.Template]

			local Trait = unitData.Trait or ""
			local TraitsConfig = UnitTraits.Traits[Trait]
			local TraitsRarityConfig = TraitsConfig and UnitRarities[TraitsConfig.Rarity] or UnitRarities["Unused Slot"]
			
			--print("PASS!")
			
			local equipped, slotIndex = (function()
				for _, s in ipairs(LOCAL_PLAYER.Hotbar:GetChildren()) do
					if s.Value == uuid then return true, s.Name end
				end
				return false, nil
			end)()

			local rarityRank = RARITY_ORDER[unitData.Rarity] or UNKNOWN_RARITY_RANK
			slotButton.LayoutOrder = equipped and tonumber(slotIndex) or (100 + rarityRank)

			local EquippedStrokeFrame = Holder:FindFirstChild("EquippedStrokeFrame")
			if equipped then
				if not EquippedStrokeFrame then
					EquippedStrokeFrame = ReplicatedStorage.Assets.Interface.UnitTemplates.StrokeFrame:Clone()
					EquippedStrokeFrame.Name = "EquippedStrokeFrame"
					EquippedStrokeFrame.Parent = Holder
				end
				EquippedStrokeFrame.Visible = true
			elseif EquippedStrokeFrame then
				EquippedStrokeFrame:Destroy()
			end

			TraitImage.Image = TraitsConfig and TraitsConfig.ImageId or ""
			TraitImage.Gradient.Color = TraitsRarityConfig.Gradient.Color
			TraitImage.Gradient.Enabled = TraitImage.Image ~= ""

			Glow.Visible = UnitDefinition.Rarity == "Secret" or UnitDefinition.Rarity == "Mythic" or UnitDefinition.Rarity == "Majesty"
			Glow.Gradient.Color = RarityConfig.Gradient.Color

			Stars.Gradient.Color = RarityConfig.Gradient.Color

			Holder.Gradient.Color = RarityConfig.Gradient.Color
			Main.Gradient.Color = RarityConfig.Gradient.Color
			
			Level.Text = unitData.Level
			UnitName.Text = unitData.Name

			local ShinyFrame = slotButton:FindFirstChild("ShinyFrame")
			if unitData.Shiny then
				if not ShinyFrame then
					ShinyFrame = ReplicatedStorage.Assets.Interface.UnitTemplates.Shine:Clone()
					ShinyFrame.Name = "ShinyFrame"
					ShinyFrame.Parent = slotButton
					ShinyFrame.UIGradient.Color = RarityConfig.Gradient.Color
				end
				ShinyFrame.Visible = true
			elseif ShinyFrame then
				UnitGradient.stopGradient(ShinyFrame.UIGradient)
				ShinyFrame:Destroy()
			end
			
			if slotButton:GetAttribute("GradientsRunning") then
				slotButton:SetAttribute("GradientsRunning", false)
				startSlotGradients(slotButton, unitData)
			end
		end

		previousUnitDataMap = unitDataMap
		updateAllFilterLabels()
	end

	local slotSpinConns = {}
	local function updateHotbarFromServer(serverData)
		for index = 1, 6 do
			local unitUUID = serverData.Hotbar[index]
			local HotbarSlot = HUDHotBar:FindFirstChild(tostring(index)) or HUDHotBar:FindFirstChild(index)
			if HotbarSlot then
				local previousUUID = HotbarSlot:GetAttribute("UUID")
				local unitChanged = previousUUID ~= (unitUUID or "")
				if unitChanged then
					HotbarSlot:SetAttribute("GradientsAnimated", false)
				end

				HotbarSlot:SetAttribute("UUID", unitUUID or "")
				HotbarSlot:SetAttribute("isHotbar", true)

				local Glow = HotbarSlot.Glow
				local PlayerIcon = HotbarSlot.PlayerIcon
				local LightRay = HotbarSlot:FindFirstChild("LightRay")
				local UnitImage = HotbarSlot.Holder.Main.UnitImage
				local ViewportFrame = UnitImage.ViewportFrame
				local LevelFrame = HotbarSlot.Holder.Main.LevelFrame
				local Level = LevelFrame.Level
				local Stars = HotbarSlot.Holder.Main.Stars
				local UnitName = HotbarSlot.Holder.Main.UnitName
				local TraitImage = HotbarSlot.Holder.Main.TraitIcon
				local Holder = HotbarSlot.Holder
				local Main = Holder.Main
				local CostLabel = Main.Price

				local unitData = serverData.Units[unitUUID]
				local RarityConfig = (unitData and UnitRarities[unitData.Rarity]) or UnitRarities["Unused Slot"]
				local UnitDefinition = unitData and UnitDatabase.Units[unitData.Template]

				local Trait = unitData and unitData.Trait or ""
				local TraitsConfig = UnitTraits.Traits[Trait]
				local TraitsRarityConfig = TraitsConfig and UnitRarities[TraitsConfig.Rarity] or UnitRarities["Unused Slot"]

				if unitData and RarityConfig and UnitDefinition then
					Holder.Visible = true
					Main.Visible = true
					PlayerIcon.Visible = false
					Stars.Visible = true
					LevelFrame.Visible = true

					local isSpecialRarity = UnitDefinition.Rarity == "Secret" or UnitDefinition.Rarity == "Mythic" or UnitDefinition.Rarity == "Majesty"
					if isSpecialRarity then
						if not LightRay then
							LightRay = ReplicatedStorage.Assets.Interface.UnitTemplates.LightRay:Clone()
							LightRay.Parent = HotbarSlot
						end
						LightRay.Visible = true
						LightRay.Gradient.Color = RarityConfig.Gradient.Color
					elseif LightRay then
						UnitGradient.stopGradient(LightRay.Gradient)
						trackedHotbarGradients[LightRay.Gradient] = nil
						if slotSpinConns[index] then
							slotSpinConns[index]:Disconnect()
							slotSpinConns[index] = nil
						end
						LightRay:Destroy()
						LightRay = nil
					end

					Glow.Visible = isSpecialRarity
					Glow.Gradient.Color = RarityConfig.Gradient.Color

					TraitImage.Image = TraitsConfig and TraitsConfig.ImageId or ""
					TraitImage.Gradient.Color = TraitsRarityConfig.Gradient.Color
					TraitImage.Gradient.Enabled = TraitImage.Image ~= ""

					Holder.Gradient.Color = RarityConfig.Gradient.Color
					Main.Gradient.Color = RarityConfig.Gradient.Color

					Level.Text = unitData.Level
					Stars.Gradient.Color = RarityConfig.Gradient.Color

					CostLabel.Visible = true
					CostLabel.Text = tostring(UnitDefinition.Cost) .. "¥"

					local ShinyFrame = HotbarSlot:FindFirstChild("ShinyFrame")
					if unitData.Shiny then
						if not ShinyFrame then
							ShinyFrame = ReplicatedStorage.Assets.Interface.UnitTemplates.Shine:Clone()
							ShinyFrame.Name = "ShinyFrame"
							ShinyFrame.Parent = HotbarSlot
							ShinyFrame.UIGradient.Color = RarityConfig.Gradient.Color
							animateHotbar(ShinyFrame.UIGradient, "OffsetXAnim")
						end
						ShinyFrame.Visible = true
					elseif ShinyFrame then
						UnitGradient.stopGradient(ShinyFrame.UIGradient)
						trackedHotbarGradients[ShinyFrame.UIGradient] = nil
						ShinyFrame:Destroy()
					end

					renderUnitInViewport(ViewportFrame, unitData, UnitDefinition, nil, true)

					if not HotbarSlot:GetAttribute("GradientsAnimated") then
						HotbarSlot:SetAttribute("GradientsAnimated", true)
						animateHotbar(TraitImage.Gradient, "OffsetXAnim")
						animateHotbar(Glow.Gradient, "OffsetXAnim")
						animateHotbar(Stars.Gradient, "OffsetXAnim")
						if LightRay then
							animateHotbar(LightRay.Gradient, "OffsetXAnim")
						end
						animateHotbar(Holder.Gradient, "OffsetXAnim")
						animateHotbar(Main.Gradient, "OffsetXAnim")
					end

					if LightRay and LightRay.Visible and not LightRay:GetAttribute("SpinConnected") then
						LightRay:SetAttribute("SpinConnected", true)
						local spinConn
						spinConn = game:GetService("RunService").Heartbeat:Connect(function(dt)
							if LightRay and LightRay.Parent then
								LightRay.Rotation = (LightRay.Rotation + dt * 60) % 360
							else
								spinConn:Disconnect()
							end
						end)
						slotSpinConns[index] = spinConn
					end

					UnitImage.Visible = true
				else
					if slotSpinConns[index] then
						slotSpinConns[index]:Disconnect()
						slotSpinConns[index] = nil
					end

					PlayerIcon.Visible = true
					Glow.Visible = false
					LevelFrame.Visible = false
					Stars.Visible = false
					UnitName.Visible = false
					TraitImage.Visible = false
					CostLabel.Visible = false
					UnitImage.Visible = false

					UnitGradient.stopGradient(TraitImage.Gradient)
					UnitGradient.stopGradient(Glow.Gradient)
					UnitGradient.stopGradient(Stars.Gradient)
					UnitGradient.stopGradient(Holder.Gradient)
					UnitGradient.stopGradient(Main.Gradient)

					trackedHotbarGradients[TraitImage.Gradient] = nil
					trackedHotbarGradients[Glow.Gradient] = nil
					trackedHotbarGradients[Stars.Gradient] = nil
					trackedHotbarGradients[Holder.Gradient] = nil
					trackedHotbarGradients[Main.Gradient] = nil

					if LightRay then
						UnitGradient.stopGradient(LightRay.Gradient)
						trackedHotbarGradients[LightRay.Gradient] = nil
						LightRay:Destroy()
					end

					local ShinyFrame = HotbarSlot:FindFirstChild("ShinyFrame")
					if ShinyFrame then
						UnitGradient.stopGradient(ShinyFrame.UIGradient)
						trackedHotbarGradients[ShinyFrame.UIGradient] = nil
						ShinyFrame:Destroy()
					end

					HotbarSlot:SetAttribute("GradientsAnimated", false)

					unloadViewport(ViewportFrame)

					Main.Gradient.Color = ColorSequence.new(Color3.fromRGB(255, 255, 255))
					Holder.Gradient.Color = ColorSequence.new(Color3.fromRGB(255, 255, 255))
				end

				UnitHover:registerUnit(HotbarSlot, function() return serverData.Units[unitUUID] end, true, LOCAL_PLAYER)
			end
		end
	end

	local lastInvokeTime = 0
	local INVOKE_COOLDOWN = 0.5

	local function updateAllSlots(optionalServerData)
		local serverData = optionalServerData
		if not serverData then
			local now = tick()
			if now - lastInvokeTime < INVOKE_COOLDOWN then
				serverData = { Units = previousUnitDataMap, Hotbar = {} }
			else
				local ok, res = pcall(function() return getUnits:InvokeServer() end)
				lastInvokeTime = now
				if not ok or not res then
					serverData = { Units = previousUnitDataMap, Hotbar = {} }
				else
					serverData = res
				end
			end
		end

		updateHotbarFromServer(serverData)
		patchInventory(serverData.Units)
	end

	local lastScan = 0
	local SCAN_INTERVAL = 0.12 -- This is when I have Units opened and how long it loads

	local function scanVisibleSlots()
		if tick() - lastScan < SCAN_INTERVAL then return end
		lastScan = tick()

		for uuid, slotInfo in pairs(InventorySlots) do
			local slotFrame = slotInfo.Frame
			if not slotFrame or not slotFrame.Parent then continue end

			local Frames = slotFrame:FindFirstChild("Holder") and slotFrame.Holder:FindFirstChild("Main")
			if not Frames then continue end
			local viewPort = Frames:FindFirstChild("UnitImage") and Frames.UnitImage:FindFirstChild("ViewportFrame")
			if not viewPort then continue end

			if not slotFrame.Visible then
				stopSlotGradients(slotFrame)
				if viewPort:GetAttribute("renderedUUID") ~= nil then
					unloadViewport(viewPort)
				end
				continue
			end

			local visible = IsVisible(UnitsInventory, slotFrame)
			local alreadyRendered = viewPort:GetAttribute("renderedUUID") == uuid

			if visible then
				startSlotGradients(slotFrame, slotInfo.unitData)
				if not alreadyRendered then
					renderUnitInViewport(viewPort, slotInfo.unitData, UnitDatabase.Units[slotInfo.unitData.Template], nil, false)
				end
			else
				stopSlotGradients(slotFrame)
				if viewPort:GetAttribute("renderedUUID") ~= nil then
					unloadViewport(viewPort)
				end
			end
		end
	end

	local heartbeatConnection
	heartbeatConnection = game:GetService("RunService").Heartbeat:Connect(function()
		if not UnitsWindow.Enabled then return end
		scanVisibleSlots()
	end)

	updateAllSlots()

	updateInventoryEvent.OnClientEvent:Connect(function(serverData)
		if serverData and type(serverData) == "table" and serverData.Units then
			updateAllSlots(serverData)
		else
			updateAllSlots()
		end

		local SelectedUUID = LOCAL_PLAYER.SelectedUnit.Value
		if SelectedUUID ~= "" and serverData and serverData.Units then
			local unitData = serverData.Units[SelectedUUID]
			if unitData then
				updateInfoPanel(unitData)
			else
				updateInfoPanel(nil)
			end
		else
			updateInfoPanel(nil)
		end

		if UnitHover and UnitHover.Refresh then
			pcall(function() UnitHover.Refresh() end)
		end
	end)

	Remotes.SelectingUnit.Event:Connect(function(returnTo)
		UnitsInventory.Visible = true
		self.SelectingUnit = returnTo
	end)
	
	local function sampleGradient(colorSequence, t)
		local keypoints = colorSequence.Keypoints
		for i = 1, #keypoints - 1 do
			local a, b = keypoints[i], keypoints[i+1]
			if t >= a.Time and t <= b.Time then
				local alpha = (t - a.Time) / (b.Time - a.Time)
				return a.Value:Lerp(b.Value, alpha)
			end
		end
		return keypoints[#keypoints].Value
	end

	local function buildGradientText(text, colorSequence)
		local result = ""
		local len = #text
		for i = 1, len do
			local t = (i - 1) / math.max(len - 1, 1)
			local color = sampleGradient(colorSequence, t)
			local hex = string.format("rgb(%d,%d,%d)", math.floor(color.R*255), math.floor(color.G*255), math.floor(color.B*255))
			result = result .. string.format('<font color="%s">%s</font>', hex, text:sub(i,i))
		end
		return result
	end
	
	local TextChatService = game:GetService("TextChatService")
	local ShinyAnnouncement = Remotes:WaitForChild("ShinyAnnouncement")
	
	ShinyAnnouncement.OnClientEvent:Connect(function(username, displayName, unitName, rarity)
		local RarityConfig = UnitRarities[rarity]
		if not RarityConfig then return end

		local plainMessage = string.format("%s (@%s) has obtained a Shiny %s!", displayName, username, unitName)
		local coloredMessage = buildGradientText(plainMessage, RarityConfig.Gradient.Color)

		local textChannels = TextChatService:WaitForChild("TextChannels")
		local generalChannel = textChannels:WaitForChild("RBXGeneral")
		generalChannel:DisplaySystemMessage(coloredMessage)
	end)

	if UnitHover then
		UnitHover:registerUnitHover({
			player = LOCAL_PLAYER,
			getUnitFromSlot = function(slot)
				if not slot then return nil end
				local uuid = slot.GetAttribute and slot:GetAttribute("UUID")
				if not uuid or uuid == "" then return end
				return previousUnitDataMap[uuid]
			end,
			getItemFromSlot = function(slot)
				if not slot then return nil end
				local name = slot.GetAttribute and slot:GetAttribute("ItemName")
				if not name or name == "" then return nil end
				local ok, ItemsModule = pcall(function()
					return files["ItemsMain"].Items[name]
				end)
				return nil
			end,
			moveThrottle = 1 / 120,
		})

		script.AncestryChanged:Connect(function()
			if not script:IsDescendantOf(game) then
				pcall(function() UnitHover.Stop() end)
			end
		end)
	end

	script.AncestryChanged:Connect(function()
		if not script:IsDescendantOf(game) then
			if heartbeatConnection and heartbeatConnection.Connected then heartbeatConnection:Disconnect() end
			for uuid, info in pairs(InventorySlots) do
				if info and info.Frame and info.Frame.Parent then
					local Frames = info.Frame:FindFirstChild("Holder") and info.Frame:FindFirstChild("Holder"):FindFirstChild("Main")
					if Frames and Frames:FindFirstChild("UnitImage"):FindFirstChild("ViewportFrame") then
						unloadViewport(Frames:FindFirstChild("UnitImage"):FindFirstChild("ViewportFrame"))
					end
					pcall(function() info.Frame:Destroy() end)
				end
			end
		end
	end)
	
	UnitsWindow:GetPropertyChangedSignal("Enabled"):Connect(function()
		if UnitsWindow.Enabled then
			updateAllSlots()
		else
			for uuid, slotInfo in pairs(InventorySlots) do
				if slotInfo.Frame then
					stopSlotGradients(slotInfo.Frame)
				end
			end

			for _, unitFrame in ipairs(UnitsInventory:GetChildren()) do
				if unitFrame:IsA("Frame") then
					local holder = unitFrame:FindFirstChild("Holder")
					local main = holder and holder:FindFirstChild("Main")
					local unitImage = main and main:FindFirstChild("UnitImage")
					local vp = unitImage and unitImage:FindFirstChild("ViewportFrame")
					if vp then unloadViewport(vp) end
				end
			end
		end
	end)
end

function UnitsMain.client:Start(files)
	local TweenService = game:GetService("TweenService")

	local HUDController = files["HUDController"]
	local InputController = files["InputController"]
	local Gradient = files["UnitGradient"]

	local LOCAL_PLAYER = game:GetService("Players").LocalPlayer
	repeat task.wait() until LOCAL_PLAYER:GetAttribute("PlayerLoaded") == true
	repeat task.wait() until LOCAL_PLAYER:GetAttribute("DataLoaded") == true

	local PlayerGui = LOCAL_PLAYER:WaitForChild("PlayerGui")
	local HUD = PlayerGui:WaitForChild("HUD")
	local Windows = PlayerGui:WaitForChild("Windows")
	local UnitsWindow = Windows:WaitForChild("Units")
	
	local lastToggle = 0
	local COOLDOWN = 0.5
	local function UnitsToggle()
		local now = tick()
		if now - lastToggle < COOLDOWN then return end
		lastToggle = now

		--self.SelectingUnit = nil
		UnitsWindow.Filters.Visible = false
		HUDController.ToggleWindow(UnitsWindow)
	end
	
	Gradient.animateGradient(UnitsWindow.Holder.Title.UIGradient, "OffsetXAnim", 2)
	Gradient.animateGradient(UnitsWindow.Holder.UIStroke.UIGradient, "OffsetXAnim", 2)
	Gradient.animateGradient(UnitsWindow.Glow.ShadowImage.UIGradient, "OffsetXAnim", 2)
	
	UnitsWindow.Holder.Info.Buttons.UnequipAll.Button.Activated:Connect(function()
		Remotes.UnEquipAllUnits:FireServer(LOCAL_PLAYER)
	end)
	
	UnitsWindow.Holder.Info.Buttons.Filters.Button.Activated:Connect(function()
		UnitsWindow.Filters.Visible = not UnitsWindow.Filters.Visible
	end)
	
	UnitsWindow.Holder.Close.Button.Activated:Connect(function()
		UnitsToggle()
	end)
	
	UnitsWindow.Filters.Close.Button.Activated:Connect(function()
		UnitsWindow.Filters.Visible = false
	end)
	
	InputController:AddFunctionToAction("ToggleUnitsInventory", "Pressed", UnitsToggle)
end

return UnitsMain

Woah man you can’t just dump an entire novel with no context and expect people to decipher it. What is SelectingUnit supposed to do? For one thing, you have it underneath “Remotes” but it appears to be a BindableEvent, not a RemoteEvent. Try deleting it an inserting a remote event of the same name and see if that helps.

Should be a better to read now.
I’ll try to do it with RemoteEvent and not a BindableEvent and will let you know.

Got it solved:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.