Answered by
4 years ago Edited 4 years ago
So I don't know how you managed to even find some of this stuff because deprecated things are hidden on the docs, so I'm just going to rewrite this for you using up-to-date methods, and then answer your question as well.
But first I need to get you to understand the purpose of variables in programming. They are not there to look at or keep a reference for yourself, they're there so you can use them in your script. You're only hurting yourself in the long run if you don't use them, and also doing things like setting the mouse to a variable and then getting the mouse all over again for no reason is slowing your script down.
So for an example, when you created the "head" variable you should have set it to just the head, and used it in the next line like so:
1 | local head = game.Workspace [ player.Name ] .Head |
2 | local mouse = CFrame.new(head.Position,mouse.Hit.p).lookVector |
Second, stop using such a roundabout way of accessing the character like searching the workspace for a character when you already have the Player as a variable. game.Workspace[player.Name]
is wrong, use player.Character
instead.
Now moving on to your question, using the notes above, and the removal of the deprecated functions you have used, it should look like this:
01 | local Player = game.Players.LocalPlayer |
02 | local Mouse = Player:GetMouse() |
03 | local FirePoint = tool.Glock.FirePoint |
04 | repeat wait() until Player:HasAppearanceLoaded() |
06 | local RayParams = RaycastParams.new() |
07 | RayParams.FilterType = Enum.RaycastFilterType.Blacklist |
08 | RayParams.FilterDescendantsInstances = Player.Character |
10 | local Direction = (FirePoint.CFrame.Position-Mouse.Hit.p).Unit |
11 | local Origin = FirePoint.CFrame.Position |
13 | local Result = workspace:Raycast(Origin,Direction* 250 ,RayParams) |
14 | local Part, Position = Result.Instance, Result.Position |
So that does exactly what you had before with all the redundant variables and deprecated functions removed. Now to get it to ignore CanCollided parts, you can either add them to the Filter or you can check during the raycasting like this:
01 | local Player = game.Players.LocalPlayer |
02 | local Mouse = Player:GetMouse() |
03 | local FirePoint = tool.Glock.FirePoint |
04 | repeat wait() until Player:HasAppearanceLoaded() |
06 | local RayParams = RaycastParams.new() |
07 | RayParams.FilterType = Enum.RaycastFilterType.Blacklist |
08 | RayParams.FilterDescendantsInstances = Player.Character:GetDescendants() |
10 | local Direction = (FirePoint.CFrame.Position-Mouse.Hit.p).Unit |
11 | local Origin = FirePoint.CFrame.Position |
13 | local Result = workspace:Raycast(Origin,Direction* 250 ,RayParams) |
14 | local Part, Position = Result.Instance, Result.Position |
15 | local DistanceToGo = 250 -(Position - Origin).Magnitude |
16 | if not Part.CanCollide then |
17 | Result = workspace:Raycast(Origin,Direction*DistanceToGo,RayParams) |
18 | Part, Position = Result.Instance, Result.Position |
It will shoot a ray out, and if it hits a part that is not CanCollided then it will shoot another ray in the same direction for the remaining distance of the original ray.
Since this answers your question, remember to mark it as the accepted answer.