#MouseHoverEnter/Leave Events Help

1 messages · Page 1 of 1 (latest)

golden moss
#

Localscript within StarterPlayerScripts

-- Imagine you place a plate with 4 peices of 'food' on a table

game.Workspace.Interact.PlacedItems.ChildAdded:Connect(function(tool)
        --Fires every time new plate added on table
  if tool:IsA("Tool") then
    if tool:FindFirstChild("Food") then
          --Checks for Food folder
      for _,v in pairs(tool.Food:GetChildren()) do
            --Loops through the food(meshparts) in folder
        local Click = v:WaitForChild("ClickDetector")
              --Defines the ClickDetector inside the meshparts

        Click.MouseHoverEnter:Connect(function()
              --Fires when players mouse hovers over the 'food'.
          print("test1") --print check
          local highlight = Instance.new("Highlight")
          highlight.FillTransparency = 1
          highlight.Adornee = Click.Parent
          highlight.Parent = Click.Parent
                --Code to run a highlight effect around the food
          print("test2") --print check 2
        end)
        Click.MouseHoverLeave:Connect(function()
              --Fires when players mouse leaves the 'food'
          print("test3") --print check 3
          Click.Parent.Highlight:Destroy()
                --Destroys the highlight effect
          print("test4") --print check 4
        end)
--More Code (unrelated)
      end
    end
  end
end)

I made code as clearly labeled as possible

NONE of the print checks run

SOME of the food will highlight while others will not
as far as i'm concerned its completely random whether or not the food highlights or not

I have tested while looking inside the meshparts folders the highlight instance will appear ONLY on the food that highlights and will not appear at all on food that does not - this means its not a highlight issue - although highlights are buggy too but theres no highlight instances spawning at all within some foods.

If anyone knows whats going on please let me know

south token
#

i didn't read the code yet but roblox has a limit of 31 highlights

golden moss
#

i know

#

dont worry i found that out after googling

#

thanks for responding btw i thought my post got forgotten about lol

south token
golden moss
#

ooh what how did i miss that

#

but

south token
#

maybe try using Mouse.Target?

golden moss
#

it doesnt fire at all

#

yeah ill try that

#

mouse.Target probably best

#

mouse hover doesnt fire print statements in my case either

golden moss
golden moss
# south token maybe try using Mouse.Target?

i didnt want to use mouse.target because i would have to do a mouse.move:Connect event to run 24/7 for every client which i didnt want to do BUT i found out that first of all i placed the Print statements in the wrong spot AND

The reason it wasnt working was actually because the food hadnt loaded in. the GetChildren event is so fast that the meshparts dont have enough time to load in so they dont get added into the for loop i fixed this by adding a task.wait(1) before it and it finally works

golden moss
#

yes already marked solved

south token
#

cool