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

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

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.

1 comment

0

The snap C0 is relative, not absolute.

1 answer

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.

1 comment

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.

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