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