Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Can I get help with mouse properties issues?

Asked by
arshad145 392 Moderation Voter
7 years ago
Edited 7 years ago

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.

01Tool.Activated:connect(function()
02    local function weld(w)
03        local We = Instance.new("Weld",chr.UpperTorso)     
04        We.Part1 = chr.UpperTorso
05        We.Part0 = w
06        We.C1 = chr.UpperTorso.CFrame:inverse()
07        We.C0 = w.CFrame * CFrame.new(0,0,0)
08 
09    end
10 
11    local x = Instance.new("Part", workspace)
12    x.Shape = "Cylinder"
13    x.BrickColor = BrickColor.Random()
14    x.CanCollide = true
15 
View all 33 lines...

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

0
Issue is fixed with raycasting. Source : [Roblox Wiki](http://wiki.roblox.com/index.php?title=Making_a_ray-casting_laser_gun#Setting_Up) arshad145 392 — 7y

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

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.

01Tool.Activated:connect(function()
02    local function weld(w)
03        local We = Instance.new("Weld",chr.UpperTorso)     
04        We.Part1 = chr.UpperTorso
05        We.Part0 = w
06        We.C1 = chr.UpperTorso.CFrame:inverse()
07        We.C0 = w.CFrame * CFrame.new(0,0,0)
08    end
09    local x = Instance.new("Part")
10    x.Shape = "Cylinder"
11    x.BrickColor = BrickColor.Random()
12    x.CanCollide = true
13    x.Parent = workspace --Parent after setting properties
14    local bg = Instance.new("BodyGyro")
15    bg.MaxTorque = Vector3.new(math.huge,math.huge,math.huge)
View all 29 lines...
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. arshad145 392 — 7y
Ad

Answer this question