[SOLVED] Part Going to Camera

I tried to make the part follow the player’s mouse but this happened:


Here’s the code:

local plr = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()

local mouse = plr:GetMouse()
local part = Instance.new("Part",workspace)
while wait() do
	
	part.Anchored = true
	part.Transparency = 0.4
	part.CFrame = CFrame.new(mouse.Hit.Position)
	
	mouse.Button1Down:Connect(function()
		
		part.Anchored = false
		part.CFrame = CFrame.new(mouse.Target.Position)
	end)
	
end

Any help is appreciated!

Hello!


Can I get a place file? Just to help make testing my code a little easier. If not, I could scramble a mock-up of what you made.

I don’t mind if I get the place file or not. Either way, I’m still glad to help!

I already solved it, but thank you! Do you still want the place file?

Ah, alright. I don’t need the place file then.


Next time if you solve it by yourself, post a reply and mark that as the solution or change the title to include “[SOLVED]” or something. Just so people don’t get confused!

Ok, that’s helpful for next time!

1 Like

I tried to make the part follow the player’s mouse but this happened:
local plr = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()

local mouse = plr:GetMouse()
local part = Instance.new(“Part”,workspace)
while wait() do
part.Anchored = true
part.Transparency = 0.4
part.CFrame = CFrame.new(mouse.Hit.Position)

mouse.Button1Down:Connect(function()
part.Anchored = false
part.CFrame = CFrame.new(mouse.Target.Position)
end)
end

You can fix this by adding a wait() at the end of the Button1Down script. This will stop the part from constantly re-anchoring itself.

you’re putting this connection in the loop which causes the part to be teleported multiple times, offsetting closer to the camera every time

I know its been solved but for those who suffer from the same problem here:

local plr = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()

local mouse = plr:GetMouse()
local part = Instance.new("Part",workspace)
local runservice = game:GetService("RunService") -- using this is more optimal
mouse.TargetFilter = part

runservice.HeartBeat:Connect(function()
	
	part.Anchored = true
	part.Transparency = 0.4
	part.CFrame = CFrame.new(mouse.Hit.Position)
	
	mouse.Button1Down:Connect(function()
		
		part.Anchored = false
		part.CFrame = CFrame.new(mouse.Target.Position)
	end)
	
end)

hi ik its late but im expereincing the same issue but do you know how do i fix it i can give you the file when you need