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

Raycasting not working?

Asked by 9 years ago
                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!

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. DigitalVeer 1473 — 9y
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! TheDarkOrganism 173 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago
  • 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

0
Its supposed to ignore everything.... DevScripting 92 — 9y
1
Including every part in the game? If you want to do that then why use Ray Casting? TheDarkOrganism 173 — 9y
0
So the laser goes through parts... Duh DevScripting 92 — 9y
Ad

Answer this question