I'm making a fighting game (another jojo game) and I'm having problems with making a hitbox using raycast. It's saying that the variable "CastResults" == nil
Extra Information: The variable "Stand" is a model, containing R6 Rigparts, it's primarypart is the HumanoidRootPart
My failed output:
ServerScriptService.StandServerHandler:233: attempt to index nil with 'Instance'
My raycast code:
local RaycastParameters = RaycastParams.new() RaycastParameters.FilterType = Enum.RaycastFilterType.Blacklist RaycastParameters.FilterDescendantsInstances = {Stand, Character} RaycastParameters.IgnoreWater = true local CastResults = Workspace:Raycast(Stand.PrimaryPart.CFrame.Position, Stand.PrimaryPart.CFrame.LookVector * 500, RaycastParameters) local Hit = CastResults.Instance -- Line 233 local HitPosition = CastResults.Position local Surface = CastResults.Normal local Material = CastResults.Material.Name
The raycast result not aways returns something, it can be nil if the ray did not find anything and ur code stops working after that.
Just check it out with
if CastResults then local Hit = CastResults.Instance local HitPosition = CastResults.Position local Surface = CastResults.Normal local Material = CastResults.Material.Name end