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

Tool aiming at Mouse.Hit. Why is this not working?

Asked by 8 years ago

So I am trying to make a tool aim towards either Mouse.Hit or Mouse.Origin. Right now, I am using Mouse.Hit, but the gun is becoming really glitchy. Why?

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

local Equipped = false

script.Parent.Equipped:connect(function()
    Equipped = true
    coroutine.resume(coroutine.create(function()
        script.Parent.Parent.Animate.Disabled = true
        Mouse.Move:connect(function()
            if Equipped == true then
                local Angles = Mouse.Hit - Mouse.Hit.p
                script.Parent.Parent.Torso["Right Shoulder"].C0 = CFrame.new(script.Parent.Parent.Torso["Right Shoulder"].C0.p, Mouse.Hit.p)
                wait()
            end
        end)
        script.Parent.Parent.Animate.Disabled = false
    end))

end)

script.Parent.Unequipped:connect(function()
    Equipped = false
end)

I feel like this should work, but instead it just flings my arm around. Also, there is no output from the script.

0
The snap C0 is relative, not absolute. BlueTaslem 18071 — 8y

1 answer

Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
8 years ago

I'm not certain of what the issue is - your code looks good.

What it might be is that coroutine. Why are you using it, anyway? It doesn't need to be there, since the callback function is spawned in its own thread when it gets called.

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

local Equipped = false

script.Parent.Equipped:connect(function()
    Equipped = true
    script.Parent.Parent.Animate.Disabled = true
    Mouse.Move:connect(function()
        if Equipped == true then
            local Angles = Mouse.Hit - Mouse.Hit.p
            script.Parent.Parent.Torso["Right Shoulder"].C0 = CFrame.new(script.Parent.Parent.Torso["Right Shoulder"].C0.p, Mouse.Hit.p)
            wait()
        end
    end)
    script.Parent.Parent.Animate.Disabled = false

end)

script.Parent.Unequipped:connect(function()
    Equipped = false
end)

Let me know if this worked for you, because there is a way to make the aiming a lot smoother than using Mouse.Move.

0
This did the exact same thing. I just want to say, I have been fiddling with it trying to get it to work. Mouse.Move was added to see if it would help at all. MisaMiner 50 — 8y
Ad

Answer this question