Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Making a part follow the mouse's position?

Asked by 8 years ago

I've got a script that does this, but it constantly keeps growing, but I don't know how to prevent this.

Here's my script:

local char = game.Players.LocalPlayer
local mouse = char:GetMouse()

while wait() do
    game.Workspace.Spotlight.SpotlightFocus.CFrame = CFrame.new(mouse.Hit.p)
    game.Workspace.Spotlight.SpotlightFocus.Size = Vector3.new(1, 1, 1)
end

1 answer

Log in to vote
0
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
8 years ago

It's not constantly growing, but rather getting closer to your screen. It's doing this because you are not ignoring that part when detecting the mouse hit position (therefore the mouse hits the top of the brick setting the part's positon closer to the camera).

To make the mouse ignore that part, you can set the mouse's TargetFilter:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.TargetFilter = game.Workspace.Spotlight

while wait() do
    game.Workspace.Spotlight.SpotlightFocus.CFrame = CFrame.new(mouse.Hit.p)
end
Ad

Answer this question