Unable to cast value to objects?
When I use this script, I get this error:
15:07:18.573 - Unable to cast value to Objects
15:07:18.573 - Script 'Players.Player1.Backpack.Chem Sniper.LocalScript', Line 14
15:07:18.574 - Stack End
How do I fix it?
01 | local tool = script.Parent |
03 | local IgnoreList = { "Handle" , "Hat" } |
06 | tool.Equipped:connect( function (mouse) |
11 | mouse.Button 1 Down:connect( function () |
13 | local ray = Ray.new(tool.AimPart.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit* 300 ) |
14 | local hit, position = game.Workspace:FindPartOnRayWithIgnoreList(ray, user) |
17 | local playerhit = game.Players:GetPlayerFromCharacter(hit.Parent) or game.Players:GetPlayerFromCharacter(hit.Parent.Parent) |
19 | local humanoid = playerhit.Character.Humanoid |
22 | if hit.Name = = "Head" then |
23 | humanoid:TakeDamage( 100 ) |
25 | humanoid:TakeDamage( 30 ) |
30 | local distance = (position - tool.AimPart.CFrame.p).magnitude |
31 | local rayPart = Instance.new( "Part" , user) |
32 | rayPart.Name = "RayPart" |
33 | rayPart.BrickColor = BrickColor.new( "Really blue" ) |
34 | rayPart.Parent = game.Workspace |
35 | rayPart.Transparency = 0.5 |
36 | rayPart.Anchored = true |
37 | rayPart.CanCollide = false |
38 | rayPart.TopSurface = Enum.SurfaceType.Smooth |
39 | rayPart.BottomSurface = Enum.SurfaceType.Smooth |
40 | rayPart.formFactor = Enum.FormFactor.Custom |
41 | rayPart.Size = Vector 3. new( 0.2 , 0.2 , distance) |
42 | rayPart.CFrame = CFrame.new(position, tool.AimPart.CFrame.p) * CFrame.new( 0 , 0 , -distance/ 2 ) |
44 | game.Debris:AddItem(rayPart, 0.1 ) |