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
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!
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.
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)