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

Raycasting not working?

				local pos = mouse.Hit.p
				local s = (pos-tool.SmokePart.Position).Magnitude
				local laser = Instance.new("Part")
				laser.Name = "Ray"
				laser.Transparency = .75
				laser.CanCollide = false
				laser.FormFactor = "Custom"
				laser.Anchored = true
				laser.BrickColor = BrickColor.new("Really black")
				laser.Size = Vector3.new(.2,.2, s)
				laser.CFrame = CFrame.new(pos, tool.SmokePart.Position)*CFrame.new(0,0,-s/2)
				game.Workspace:FindPartOnRayWithIgnoreList(laser, {game.Workspace})
				laser.Parent = workspace
				game.Debris:AddItem(laser, .75)

The third to last line is the only error printing out "Unable to cast value to Object" can you guys help me and explain to me why this doesnt work, I have multiple versions of the second to last line but I need some help, Thank You!

2 comments

0

Your issue is actually line 12. First off, you aren't storing that in anything and second off, I don't think you can put workspace as an ignorable object.

0

You can put anything that is under "game" the list ignores all descendants of the objects in the table, putting "Workspace" in the table just makes the Ray Casting function useless!

1 answer

  • I hope this helps you
local ray = Ray.new(Vector3.new(0, 0, 0), Vector3.new(0, -1, 0)) -- Shoots down from the center of the game

local laser = Instance.new('Part')
--[[
	The laser must be a Ray not a part!
--]]

game.Workspace:FindPartOnRayWithIgnoreList(ray, {laser})

-- If you have Workspace in the table it will ignore every part in the Workspace!!

Rays

A good example

The main function you are using

3 comments

0

Its supposed to ignore everything....

1

Including every part in the game? If you want to do that then why use Ray Casting?

0

So the laser goes through parts... Duh

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