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

Problem with mouse.hit rising?

Asked by 8 years ago

Hello, When i try to use mouse.hit it keeps going towards the camera. How would i fix this?

script.Parent.Activated:connect(function()
    local mouse = game.Players.LocalPlayer:GetMouse()
    mouse.keyDown:connect(function(key)
        if key == "i" then
            local Highlight = Instance.new("Part",workspace)
                Highlight.Anchored = true   Highlight.CanCollide = false
                Highlight.Size = Vector3.new(2.5,.1,2.5)
            while wait() do
                if mouse.hit.p then
                    local Ignore = {script.Parent,game.Players.LocalPlayer.Character}
                    local Ray = Ray.new(script.Parent.Handle.CFrame.p,(mouse.Hit.p - script.Parent.Handle.CFrame.p).Unit*50)
                        local Part,Position = workspace:FindPartOnRayWithIgnoreList(Ray,Ignore,false,true)
                    Highlight.CFrame = CFrame.new(Position.X,Position.Y,Position.Z)
                end
            end
        end
    end)
end)

1 answer

Log in to vote
0
Answered by
XAXA 1569 Moderation Voter
8 years ago

It's because the ray is hitting Highlight. Add Highlight to the ignore list.

local Ignore = {script.Parent,game.Players.LocalPlayer.Character, Highlight}
0
I can't belive i missed that. raspyjessie 117 — 8y
Ad

Answer this question