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

Im making a raycasting gun, but I keep on getting the same error, what is the problem?

Asked by 5 years ago

Error in output: 14:11:08.293 - Unable to cast value to Objects

--// Varialbes \\--
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local tool = script.Parent

tool.Equipped:Connect(function(equip)
    print("Player has equiped the gun!")

    mouse.Button1Down:Connect(function()
        local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 300)
        local part, position = workspace:FindPartOnRayWithIgnoreList(ray, player.Character)
        if part then print(part.Name)

        end
    end)
end)

1 answer

Log in to vote
0
Answered by
Fad99 286 Moderation Voter
5 years ago
--// Varialbes \\--
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local tool = script.Parent

tool.Equipped:Connect(function(equip)
    print("Player has equiped the gun!")

    mouse.Button1Down:Connect(function()
        local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 300)
        local part, position = workspace:FindPartOnRayWithIgnoreList(ray, {player.Character})
        if part then print(part.Name)

        end
    end)
end)

When making a ray with an ignore list, the second parameter has to be a table.

1
Thanks so much! Now I know how to make a gun, now im gonna see whats next in my scripting journey! mdbaten2 24 — 5y
0
Welcome!!! Fad99 286 — 5y
Ad

Answer this question