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

Unable to cast value to object?

Asked by 9 years ago

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?

01local tool = script.Parent
02local user
03local IgnoreList = {"Handle", "Hat"}
04 
05 
06tool.Equipped:connect(function(mouse)
07 
08   user = tool.Parent
09 
10 
11   mouse.Button1Down:connect(function()
12 
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)
15 
View all 47 lines...

1 answer

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
9 years ago

The second argument of FindPartOnRayWithIgnoreList has to be a table of parts. Replace user with a list of all of the parts inside of user.

edit: If you use FindPartOnRay instead, you don't have to change anything else, because the second argument can be an instance.

0
Or, use FindPartOnRay instead BlueTaslem 18071 — 9y
0
I tried doing that, but now it's not doing anyting. Also, @BlueTaslem, That was what I was originally going with, but it had issues with detecting shots to the head. phoniex 0 — 9y
Ad

Answer this question