I’m trying to make the mouse detect when it hits a drawer, but I noticed the updating on RenderStepped is very delayed and even occasionally pauses while the rest of the game runs fine.
local players = game:GetService("Players")
local player = players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char.Humanoid or char:FindFirstChild("Humanoid")
local mouse = player:GetMouse()
local cam = workspace.CurrentCamera
local drawer = workspace.Drawer
local point = Instance.new("Attachment")
function update()
local orgin = cam.CFrame.Position
local direction = mouse.Hit.Position - orgin
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {char, cam}
point.Parent = workspace
point.Visible = true
local newRay = workspace:Raycast(orgin, direction, params)
if newRay then
print(newRay.Instance)
point.WorldPosition = newRay.Position
if newRay.Instance == drawer then
drawer.Highlight.Enabled = true
else
drawer.Highlight.Enabled = false
end
end
end
game:GetService("RunService").RenderStepped:Connect(update)