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

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

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

✓ Accepted answer
--// 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.

2 comments

1

Thanks so much! Now I know how to make a gun, now im gonna see whats next in my scripting journey!

0

Welcome!!!

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