well, in resume, every respond i did like. lol, i make some examples on client and make a vizualice, ig i have to use more “run service” on my hitbox system with multiple methods, cuz is more accurate instead of a for loop
getpartinbox (one that i used, but im wanna updated it to this version):
local player = game:GetService("Players").LocalPlayer or game:GetService("Players").PlayerAdded:Wait()
local Character = player.Character
local humanoidroot = Character:FindFirstChild("HumanoidRootPart")
local function se()
local CharacterCF = humanoidroot.CFrame
local CharacterSize = humanoidroot.Size
local Params = OverlapParams.new()
Params.FilterType = Enum.RaycastFilterType.Exclude
Params.FilterDescendantsInstances = {Character}
local hitbox = Instance.new("Part")
hitbox.CanCollide = false
hitbox.Transparency = 0.5
hitbox.Color = Color3.new(1,0,0)
hitbox.Anchored = true
hitbox.CFrame = CharacterCF + CharacterCF.LookVector * CharacterSize.Z * 6
hitbox.Size = CharacterSize
hitbox.Parent = workspace
game:GetService("Debris"):AddItem(hitbox, .2)
local Cast = workspace:GetPartBoundsInBox(CharacterCF + CharacterCF.LookVector * CharacterSize.Z * 6, CharacterSize, Params)
if Cast then
for _, part in Cast do
local Character = part:FindFirstAncestorWhichIsA("Model")
local Humanoid = Character and Character:FindFirstChildWhichIsA("Humanoid")
if Humanoid then
print("lol")
hitbox:Destroy()
break
end
end
end
end
game:GetService("RunService").RenderStepped:Connect(se)
spherecast (the one that i like less, cuz if i get close is very weird):
local player = game:GetService("Players").LocalPlayer or game:GetService("Players").PlayerAdded:Wait()
local function createRayVisualization(startPos, endPos)
local part = Instance.new("Part")
part.Anchored = true
part.CanCollide = false
part.Material = Enum.Material.Neon
part.Color = Color3.new(1, 0, 0)
part.Size = Vector3.new(0.1, 0.1, (endPos - startPos).Magnitude)
part.CFrame = CFrame.new(startPos, endPos) * CFrame.new(0, 0, -part.Size.Z / 2)
part.Parent = workspace.Effects
print(part.Size.Z)
game:GetService("Debris"):AddItem(part, 0.1) -- Remove the part after 0.1 seconds
end
local function raycastc(origin: Vector3, radius: number, direction: Vector3, distance: number, filterType, filterTable)
local raycastParameters = RaycastParams.new()
raycastParameters.FilterType = filterType
raycastParameters.FilterDescendantsInstances = filterTable
raycastParameters.IgnoreWater = true
local raycastResult = workspace:Spherecast(origin, radius, direction * distance, raycastParameters)
if raycastResult ~= nil then
return raycastResult
else
return "Nothing was hit"
end
end
local distance = 5
local alreadyhit = {}
local function monkey()
local origin = player.Character.HumanoidRootPart.Position
local direction = player.Character.HumanoidRootPart.CFrame.LookVector
local raycastResult = raycastc(
origin,
5,
direction,
distance,
Enum.RaycastFilterType.Exclude,
{
workspace.Effects,
workspace.Map,
player.Character
}
)
local rac = raycastResult.Instance
if raycastResult ~= "Nothing was hit" then
if rac.Parent:IsA("Workspace") then return end
if rac.Parent:IsA("Accessory") or rac.Parent:IsA("Hat") or rac.Parent:IsA("BasePart") then
rac = rac.Parent
end
createRayVisualization(origin, raycastResult.Position)
if rac.Parent.Humanoid then
if not alreadyhit[rac.Parent.Humanoid] then
print("monkey")
end
end
end
end
game:GetService("RunService").RenderStepped:Connect(monkey)
shapecast (this one i really really like):
local player = game:GetService("Players").LocalPlayer or game:GetService("Players").PlayerAdded:Wait()
local root = player.Character.HumanoidRootPart
local function createRayVisualization(startPos, endPos)
local part = Instance.new("Part")
part.Anchored = true
part.CanCollide = false
part.Material = Enum.Material.Neon
part.Color = Color3.new(1, 0, 0)
part.Size = Vector3.new(0.1, 0.1, (endPos - startPos).Magnitude)
part.CFrame = CFrame.new(startPos, endPos) * CFrame.new(0, 0, -part.Size.Z / 2)
part.Parent = workspace.Effects
print(part.Size.Z)
game:GetService("Debris"):AddItem(part, 0.1) -- Remove the part after 0.1 seconds
end
-- Function to visualize ShapeCast
local function createShapeCastVisualization(startPos, endPos, radius)
local part = Instance.new("Part")
part.Anchored = true
part.CanCollide = false
part.Material = Enum.Material.Neon
part.Color = Color3.new(0, 1, 0)
part.Size = Vector3.new(radius * 2, radius * 2, (endPos - startPos).Magnitude)
part.CFrame = CFrame.new(startPos, endPos) * CFrame.new(0, 0, -part.Size.Z / 2)
part.Parent = workspace.Effects
game:GetService("Debris"):AddItem(part, 0.1) -- Remove the part after 0.1 seconds
end
local radius = 2
local function raycastc(origin: Vector3, direction, distance, filterType, filterTable)
local raycastParameters = RaycastParams.new()
raycastParameters.FilterType = filterType
raycastParameters.FilterDescendantsInstances = filterTable
raycastParameters.IgnoreWater = true
local raycastResult = workspace:Shapecast(origin, direction * distance, raycastParameters)
if raycastResult ~= nil then
return raycastResult
else
return "Nothing was hit"
end
end
local distance = 10
local alreadyhit = {}
local part = Instance.new("Part",workspace.Effects)
part.Size = Vector3.new(9,5,0)
part.Color = Color3.new(0, 0, 1)
part.Name = player.Name.. "Hitbox"
part.Transparency = 0.5
part.CanCollide = false
part.Anchored = false
part.Massless = true
local weld = Instance.new("Motor6D")
weld.Parent = root
weld.Part0 = root
weld.Part1 = part
weld.Name = "joinhitbox"
local function monkey()
local origin = part
local root_cframe = origin.CFrame
local root_size = origin.Size
local direction = root_cframe.LookVector
local raycastResult = raycastc(
origin,
direction,
distance,
Enum.RaycastFilterType.Exclude,
{
workspace.Effects,
workspace.Map,
player.Character
}
)
local rac = raycastResult.Instance
if raycastResult ~= "Nothing was hit" then
if rac.Parent:IsA("Workspace") then return end
if rac.Parent:IsA("Accessory") or rac.Parent:IsA("Hat") or rac.Parent:IsA("BasePart") then
rac = rac.Parent
end
createShapeCastVisualization(origin.Position, raycastResult.Position, radius)
if rac.Parent.Humanoid then
if not alreadyhit[rac.Parent.Humanoid] then
print("monkey")
end
end
end
end
game:GetService("RunService").RenderStepped:Connect(monkey)
for any modifications, or make it better it could be really nice, sorry for being late, too busy in life