I would like to make my monster only be able to hit the player once, however with the method ive found it just makes the monster not able to hit them multiple times every raycast. It would be helpful if any of you could just tell me what i should try, but if you could fix the script that would be wonderful.
function rusher.FindPlayers(model, damage, raycast)
if not model then return end
local players = playerService:GetPlayers()
local charactersTable = {}
for i, player in ipairs(players) do
if player.Character then
table.insert(charactersTable, player.Character)
end
local overlapParams = OverlapParams.new()
overlapParams.FilterType = Enum.RaycastFilterType.Include
overlapParams.FilterDescendantsInstances = charactersTable
local collisions = workspace:GetPartsInPart(model.Hitbox, overlapParams)
for index, obj in ipairs(collisions) do
if obj.Name == "HumanoidRootPart" then
print("InHitbox")
if not raycast then
print("BypassedRaycast")
obj.Parent.Humanoid.Health -= damage
end
local rayDirection = obj.Position - model.PrimaryPart.Position
local result = workspace:Raycast(model.PrimaryPart.Position, rayDirection)
if result and result.Instance then
local hit = result.Instance
if hit == obj or hit.Parent == obj.Parent then
if table.find(charactersTable, obj.Parent) ~= nil then
obj.Parent.Humanoid.Health -= damage
table.remove(charactersTable, table.find (charactersTable, obj.Parent) )
end
end
end
end
end
end
end
Also this may be the wrong category? Im not sure… Also the monster is like rush from doors, if that helps.