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

Can I get help with mouse properties issues?

Hello, I want an instance ; a part , to face the mouse once a tool is activated. I have tried many trigonometric functions but it is still not pointing towards my mouse once it is fired.It is a simple script because I am new to RbxLua. I have already searched in the forums , on the roblox wiki and Google'd the issue , but no result till now.

Tool.Activated:connect(function()
	local function weld(w)
		local We = Instance.new("Weld",chr.UpperTorso)		
		We.Part1 = chr.UpperTorso
		We.Part0 = w
		We.C1 = chr.UpperTorso.CFrame:inverse()
		We.C0 = w.CFrame * CFrame.new(0,0,0)
		
	end	
		
	local x = Instance.new("Part", workspace)
	x.Shape = "Cylinder"
	x.BrickColor = BrickColor.Random()
	x.CanCollide = true	
	
	local bg = Instance.new("BodyGyro",x)
	bg.MaxTorque = Vector3.new(math.huge,math.huge,math.huge)
	bg.P = 10000
	
	local bp = Instance.new("BodyPosition", x)
	bp.Position = mouse.Hit.p
	x.CFrame = CFrame.new(x.CFrame.p , mouse.Hit.p)
	
	for i = 1 , 200 do 
		wait()
		
		x.Transparency = x.Transparency + 0.0005
		
	end
		
	weld(x)	
	d:AddItem(x, 10)
end)

Thank you for your time. P.S : Runs in a local script, no errors , FilteringEnabled is OFF.

1 comment

0

Issue is fixed with raycasting. Source : Roblox Wiki

1 answer

Use this CFrame constructor for the BodyGyro, not the part's CFrame:

  • CFrame.new( [Vector3] origin , [Vector3] focus )

And due to how ROBLOX handles property listeners, you should set all properties prior to settig the object's parent. See here for more info.

Tool.Activated:connect(function()
	local function weld(w)
		local We = Instance.new("Weld",chr.UpperTorso)      
		We.Part1 = chr.UpperTorso
		We.Part0 = w
		We.C1 = chr.UpperTorso.CFrame:inverse()
		We.C0 = w.CFrame * CFrame.new(0,0,0)
	end 
	local x = Instance.new("Part")
	x.Shape = "Cylinder"
	x.BrickColor = BrickColor.Random()
	x.CanCollide = true 
	x.Parent = workspace --Parent after setting properties
	local bg = Instance.new("BodyGyro")
	bg.MaxTorque = Vector3.new(math.huge,math.huge,math.huge)
	bg.P = 10000
	local bp = Instance.new("BodyPosition")
	bp.Position = mouse.Hit.p
	bg.CFrame = CFrame.new(x.CFrame.p , mouse.Hit.p) --set gyro's cf, not part
	bg.Parent = x --Parent after setting properties
	bp.Parent = x
	x.Parent = workspace
	for i = 0,1,.05 do 
		wait()
		x.Transparency = i
	end
	weld(x) 
	d:AddItem(x, 10)
end)

1 comment

0

Thank you for the heads up on roblox handling parents, but : "Issue not resolved." This problem is not fixed , part still turns the wrong face when I click. Oh well , I will try a ray caster instead. Thank you for trying to help.

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