FindPartOnRayWithIgnoreList is deprecated, try not to use that (Use the RayCast result & RaycastParams instead)
Try this script?
–Create a part above player head
local hitbox = game.ReplicatedStorage.KiroDF.Hitbox:Clone()
hitbox.Parent = plr.Character.UpperTorso
hitbox.CFrame = wind1.CFrame * CFrame.new(0,30,0)
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {hitbox}
local Direction = hitbox.CFrame.LookVector * 50
–Cast a ray from that part
while wait() do
if plr.Character.UpperTorso:FindFirstChild("Hitbox") then
local RayResult = workspace:RayCast(hitbox.Position, Direction, raycastParams)
if RayResult then
print("Part result hit: "..RayResult.Instance)
local HitPart = RayResult.Instance
local Model = HitPart.Parent
if Model:FindFirstChild("Humanoid") and Model.Humanoid.Health > 0 then
Model.Humanoid:TakeDamage(25)
print("Damage activated")
end
else
print("No result found")
end
else
break
end
end
I think you’re trying to fire rays from the entire surface on the part rather than from a point. To do this, you’ll have to use part.Size.X and part.Size.Z to randomly determine a random position below the part’s surface. Note that parts which are slightly angled may have to use a little more complicated method.
error : RayCast is not a valid member of Workspace"Workspace"
at this line : local RayResult = workspace:RayCast(hitbox.Position, Direction, raycastParams)
I want myself to be excluded from the raycast but now it’s not detect any humanoid
while wait() do
if plr.Character.UpperTorso:FindFirstChild("Hitbox") then
local RayResult = workspace:Raycast(hitbox.Position, Direction, raycastParams)
if RayResult then
print(RayResult.Instance.Parent.Name)
--when ray cast it will print "Workspace"
print(RayResult.Instance.Parent.Name)
--when ray cast it will print "Part"
if RayResult.Instance.Parent:FindFirstChild("Humanoid") and RayResult.Instance.Parent.Humanoid.Health > 0 then
RayResult.Instance.Parent.Humanoid:TakeDamage(25)
print("Damage activated")
end
else
print("No result found")
end
else
break
end
end
error : attempt to index nil with ‘GetAccessories’ (there are end for ‘for i, v…’ above these lines)
for i ,v in pairs(game.Workspace:GetChildren()) do
local huma = v:FindFirstChild("Humanoid")
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {plr.Character, hitbox, huma:GetAccessories()}
local hitbox = game.ReplicatedStorage.KiroDF.Hitbox:Clone()
hitbox.Parent = plr.Character.UpperTorso
hitbox.CFrame = wind1.CFrame * CFrame.new(0,30,0)
for i ,v in pairs(game.Workspace:GetChildren()) do
local huma = v:FindFirstChild("Humanoid")
if huma then
local ac = v.Humanoid:GetAccessories()
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {hitbox, ac, plr.Character}
while wait() do
if plr.Character.UpperTorso:FindFirstChild("Hitbox") then
local VCharacter = game.Workspace:FindFirstChild(plr.Name)
local vPlayer = game.Players:GetPlayerFromCharacter(VCharacter)
local randomPosition = hitbox.Position + Vector3.new(math.random(-hitbox.Size.X / 2, hitbox.Size.X / 2), -hitbox.Size.Y, math.random(-hitbox.Size.Z / 2, hitbox.Size.Z / 2))
local RayResult = workspace:Raycast(randomPosition, hitbox.Position * Vector3.new(0,-200,0), raycastParams)
if RayResult then
print("test1 : "..RayResult.Instance.Parent.Name)
print("test2 : "..RayResult.Instance.Name)
if RayResult.Instance.Parent.Parent:FindFirstChild("Humanoid") and not RayResult.Instance.Parent.Parent:FindFirstChild("CheckSmash")then
local check = Instance.new("BoolValue")
check.Name = "CheckSmash"
check.Parent = RayResult.Instance.Parent.Parent
game.Debris:AddItem(check, 0.5)
tagEnemy(RayResult.Instance.Parent.Parent:FindFirstChild("Humanoid"),vPlayer)
RayResult.Instance.Parent.Parent.Humanoid:TakeDamage(25)
wait(0.05)
untagEnemy(RayResult.Instance.Parent.Parent:FindFirstChild("Humanoid"))
print("damagedone")
end
end
else
break
end
end
end
end
Instead, if you hit an accessory, you know the ancestor of the part is at least a model to find the character. Using FindFirstAncestorOfClass would totally help.