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

How to make a certain brick follow your mouse using Body Gyro/Body Positioning? (New Issue)

Alright so I attempted to do everything as I was instructed. The brick or the "Handle" will not follow the mouse. I checked my output box and it replied "Bad Cast" The brick would then fly off somewhere beyond the horizon. When I want to follow the mouse. I do believe I did the Loop function incorrectly, help would be appreciated! :D

bin = script.Parent 
player = script.Parent.Parent.Parent
me = script.Parent.Parent.Parent
local LocalPlayer = game.Players.LocalPlayer
Mouse = LocalPlayer:GetMouse()

function Talk(msg)
game:GetService("Chat"):Chat(player.Character.Head, msg, Enum.ChatColor.Red)
end

function onButton1Down(mouse)
if not enabled then
		return
	end

	local player = game.Players.LocalPlayer
	if player == nil then return end

enabled = false
	
enabled = false

		for i = 1, 1 do	
local	x2 = script.Handle:clone()
		x2.Name = "Fire" 
		x2.CanCollide = false
		x2.Anchored = false
		x2.Transparency = 0
		x2.Parent = game.Workspace
		game.Debris:AddItem(x2, 4)
		x2.CFrame = game.Players.LocalPlayer.Character.Head.CFrame*CFrame.new(0,0,0)

local	BodyGyro = Instance.new("BodyGyro")
		BodyGyro.Parent = x2
		BodyGyro.D = 5000
		BodyGyro.MaxTorque = Vector3.new(90,90,90)
		BodyGyro.P = 300
		
		
local	BodyPos = Instance.new("BodyPosition")
		BodyPos.Parent = x2
		BodyPos.D = 1250
		BodyPos.maxForce = Vector3.new (2000,2000,2000)
		BodyPos.P = 1000
		BodyPos.Position = Vector3.new (mouse)
		
			end
		
		while true do
		
		mouse.target = Mouse
		mouse.hit.p = Mouse

			wait(.1)
			end		

		
wait()
           
	wait(5)
enabled = true
	end
	

enabled = true
function onS(mouse) 
mouse.Button1Down:connect(function() onButton1Down(mouse) end) 
end 
bin.Selected:connect(onS)

1 answer

  • Get your Mouse object. This can be from your tool, or from LocalPlayer:GetMouse(), but you need your Mouse object.
  • Set a loop checking where Mouse.hit is. This is where your Mouse is pointed in the world. I'd make sure that Mouse.Target exists first though so that you're not pointing into the skybox.
  • Set your BodyGyro and BodyPosition or whatever to point to Mouse.hit. If you need a Vector3, it's Mouse.hit.p because Mouse.hit is a CFrame.

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