This is not my own gun system, I’m using ACS.
I’ve made a target that when touched, lightens a part. It works for most things but does not for guns mostly because they use raycasting. How would I detect a bullet/raycast from a gun hitting the character?
Here’s a video:
You can use the Instance of the raycast result (what the raycast touches) :
local raycastResult = workspace:Raycast() -- Put in your raycast info
if raycastResult.Instance.Parent == Target then -- The dummy target
-- raycastResult.Instance is going to be a body part, so light up whatever body part it is on the screen (i.e. arm or leg)
end
local raycastParams = RaycastParams.new({CastingPart}, Enum.RaycastFilterType.Blacklist)
local raycastResult = workspace:Raycast(origin, direction, raycastParams)
if raycastResult.Instance.Parent == Target then -- The dummy target
-- raycastResult.Instance is going to be a body part, so light up whatever body part it is on the screen (i.e. arm or leg)
end
But I can’t go into the ACS Engine script a modify because it’s over a 1000 lines of code, I need something that detects the gun shot. I’m using a .Touched event right now but it doesn’t work. If you know how ACS Engine guns fire, it would be helpful but I think it is a raycast. I want to put a script in the part that is going to be hit by the raycast (not creating it).
As far as I know, you can’t actually detect from a part itself if it’s being hit by a ray cast from somewhere else. The only way is to find out from the ray cast itself so you would need to look in the code i guess.
As far as I’m aware, there isn’t a way. ACS uses raycasting and I don’t think it has anything for this. A possible solution would be to turn each part of the humanoid into a Model, add a Humanoid to that, then detect when the health changed. I haven’t used ACS, so note this only works if the ACS has support for non-player characters.
As a side note, it potentially wouldn’t be that hard to look for where the raycasting happens and add a bit to send that data through a bindable. It might be much more difficult if the ACS uses client sided hit scanning though.