I want to detect when a player stops hover a model, I have the model saved in a variable lastTarget. I can detect hovering over it, or another model, but I can’t figure out how to detect whenever it stops hovering:
video-20230815.wmv (278,8 KB)
Here’s my LocalScript:
local function ApplyHighlight(model)
local highlight = Instance.new("Highlight")
highlight.Parent = model
highlight.OutlineColor = Color3.new(1,0,0)
lastRender = highlight
end
RunService.RenderStepped:Connect(function()
if canRender then
local mousePosition = UserInputService:GetMouseLocation()
local mouseRay = currentCamera:ViewportPointToRay(mousePosition.X, mousePosition.Y)
local filterTable = {}
for i, item in pairs(game.Workspace.Items:GetChildren()) do
if item and item:IsA("Model") and item:FindFirstChild("Owner").Value == player.Name and not table.find(filterTable, item) then
table.insert(filterTable, item)
end
end
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Include
raycastParams.FilterDescendantsInstances = filterTable
local raycastResult = game.Workspace:Raycast(mouseRay.Origin, mouseRay.Direction * 1000, raycastParams)
if raycastResult and raycastResult.Instance and not raycastResult.Instance:FindFirstAncestorWhichIsA("Model"):FindFirstChild("Highlight") then
if not lastRender then
local model = raycastResult.Instance:FindFirstAncestorWhichIsA("Model")
ApplyHighlight(model)
lastTarget = model
else
lastRender:Destroy()
lastRender = nil
end
end
else
if lastRender then
lastRender:Destroy()
lastRender = nil
end
end
end)