Thank you, I see that you are using Knit Framework! The game I originally made this module for runs completely off knit. What I would do differently is adding in some sort of listener
for example:
CollectionService:GetInstanceAddedSignal("3DHighlightUI"):Connect(function(newObject)
task.spawn(HandleHighlight, newObject)
end)
This will dynamically update when parts are changed/added.
Another one of my recommendations would be adding in an attribute system like what you did with the enabling, if my previous recommendation fails.
for example:
local hoverObject = MouseCastPlus.new(Object)
Object:SetAttribute("HoverActive", false)
hoverObject:onHoverEnter(function(part)
if not Object:GetAttribute("HoverActive") then
Object:SetAttribute("HoverActive", true)
-- logic for enter
end
end)
hoverObject:onHoverLeave(function(part)
if Object:GetAttribute("HoverActive") then
Object:SetAttribute("HoverActive", false)
-- logic for leave
end
end)
Thank you for using my module! Tell me if these recommendations help at all! I will quickly show some of the code I wrote for when I used knit for my system, in summary, I created a system that allows you to choose a card, each card is a different monster with different advantages and disadvantages.
For the KnitInit function i wrote:
function MonsterController:KnitInit()
RoundService = Knit.GetService("RoundService")
MonsterService = Knit.GetService("MonsterService")
CurrencyService = Knit.GetService("CurrencyService")
local cardChoices = {}
MonsterService.StartMonsterDeck:Connect(function(cards)
table.clear(cardChoices)
for _, v in pairs(cards) do
table.insert(cardChoices, v)
end
coroutine.wrap(function()
TimerUI:SetAttribute("Enabled", false)
ChooseUI.Enabled = true
FadeFrameChooseUI.Visible = true
FadeFrameChooseUI.BackgroundTransparency = 1
PlaySound("Fade")
tweenService:Create(FadeFrameChooseUI, TweenInfo.new(1), {BackgroundTransparency = 0}):Play()
task.wait(1)
TimerUI:SetAttribute("Enabled", false)
LightingEvent:Fire("ChooseMonster")
enableCameraTilt(workspace.Map.Cinematics.CardSelector.Camera)
cam.FieldOfView = 70
PlaySound("Fade")
tweenService:Create(FadeFrameChooseUI, TweenInfo.new(1), {BackgroundTransparency = 1}):Play()
task.wait(1)
FadeFrameChooseUI.Visible = false
end)()
task.wait(3)
AppearCards(cards)
end)
MonsterService.EndMonsterDeck:Connect(function()
ChooseUI.Enabled = false
disableCameraTilt()
TimerUI:SetAttribute("Enabled", true)
if #workspace.Map.Game:GetChildren() > 0 then
for _, v in pairs(workspace.Map.Game:GetChildren()) do
if v:IsA("Folder") and v:FindFirstChild("Map") then
LightingEvent:Fire(v.Name)
end
end
end
workspace.Map.Cinematics.CardSelector.Cards:ClearAllChildren()
currentSelected = nil
table.clear(cardChoices)
task.spawn(CleanHoverCards)
end)
MonsterService.StartMonsterGameplay:Connect(function(card)
Active = true
task.spawn(InitCameraController, card)
end)
MonsterService.EndMonsterGameplay:Connect(function()
Active = false
task.spawn(EndCameraController)
end)
MonsterService.UpdateCountdown:Connect(function(currentTime)
TimeText.Text = tostring(currentTime)
end)
MonsterService.Select:Connect(function(card)
warn(`recieved, selected card is {card.Name}`)
CurrentMonsterSelected = card
end)
UserInputService.InputBegan:Connect(function(input)
if Active == true and player:GetAttribute("IsMonster") == true and game.Workspace:GetAttribute("InGame") == true and player.Character and player.Character.Humanoid and player.Character.Humanoid.Health > 0 then
if input.KeyCode == Enum.KeyCode.Z or input.KeyCode == Enum.KeyCode.ButtonL1 then
if player.CameraMode == Enum.CameraMode.LockFirstPerson then
player.CameraMode = Enum.CameraMode.Classic
local currentCFrame = cam.CFrame
local lookVector = currentCFrame.LookVector
local flatLookVector = Vector3.new(lookVector.X, 0, lookVector.Z).Unit
cam.CFrame = CFrame.new(currentCFrame.Position + Vector3.new(0,0.35,0), currentCFrame.Position + flatLookVector)
else
player.CameraMode = Enum.CameraMode.LockFirstPerson
end
elseif input.KeyCode == Enum.UserInputType.MouseButton1 or input.KeyCode == Enum.KeyCode.ButtonR2 then
-- attack
if CurrentMonsterSelected then
end
end
end
end)
end
Then I made these functions
local currentSelected
local HoverCards = {}
local function setupCards()
local cardHitboxes = {}
for _, card in pairs(workspace.Map.Cinematics.CardSelector.Hitboxes:GetChildren()) do
table.insert(cardHitboxes, card)
end
local hoverCards = MouseCastPlus.new(cardHitboxes)
table.insert(HoverCards, hoverCards)
hoverCards:onHoverEnter(function(card)
local cardmodel = getCardModelFromHitbox(card)
task.spawn(hoveringEffectsCards, cardmodel, true)
end)
hoverCards:onHoverLeave(function(card)
local cardmodel = getCardModelFromHitbox(card)
task.spawn(hoveringEffectsCards, cardmodel, false)
end)
hoverCards:onClick(function(card)
local cardmodel = getCardModelFromHitbox(card)
local cardName = cardmodel.Name
currentSelected = cardName
MonsterService.Select:Fire(cardName)
end)
end
local function CleanHoverCards()
for _, HoverCard in pairs(HoverCards) do
HoverCard:Destroy()
end
table.clear(HoverCards)
end
What I provided works for me and my game, and this might maybe help you with yours. Goodluck!