I was trying to learn a bit with raycast on the wiki and for some reason this isn't working
local tool = script.Parent local player = game:GetService("Players").LocalPlayer tool.Equipped:connect(function(mouse) print("Tool equipped!") mouse.Button1Down:connect(function() print("Mouse pressed!") local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 300) local part, position = workspace:FindPartOnRay(ray, player.Character, false, true) local beam = Instance.new("Part", workspace) beam.BrickColor = BrickColor.new("Bright red") beam.FormFactor = "Custom" beam.Material = "Neon" beam.Transparency = 0.25 beam.Anchored = true beam.Locked = true beam.CanCollide = false local distance = (tool.Handle.CFrame.p - position).magnitude beam.Size = Vector3.new(0.3, 0.3, distance) beam.CFrame = CFrame.new(tool.Handle.CFrame.p, position) * CFrame.new(0, 0, -distance / 2) game:GetService("Debris"):AddItem(beam, 0.1) end) end)
I am getting one errors: 19:39:24.174 - Equipped is not a valid member of Part 19:39:24.175 - Script 'Players.Player1.Backpack.Gun.Handle.LocalScript', Line 4
You put your tool variable as the parent of your localscript, which is in the handle. Instead, your tool variable should be "script.parent.parent," or you should actually put your localscript directly into the gun tool.