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.

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.

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.

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