Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Making a part follow the mouse's position?

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

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.