How would I use GetPartsInPart() to replace .Touched in this hitbox script. I generally have no idea where to start or how to use it. All help is appreciated!
local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")
local db = false
local plrs = game:GetService("Players")
local plr = plrs:GetPlayers()[1] or plrs.PlayerAdded:Wait()
local touched = false
script.Parent.HitBoxEvent.OnServerEvent:Connect(function()
if db then return end
db = true
local Hitbox = Instance.new("Part")
Hitbox.Parent = script.Parent.Parent
Hitbox.CFrame = script.Parent.Parent.HumanoidRootPart.CFrame * CFrame.new(0, 0, -1)
Hitbox.Transparency = 1
Hitbox.Anchored = true
Hitbox.Size = Vector3.new(7, 7, 5)
Hitbox.CanCollide = false
Hitbox.Touched:Connect(function(hit)
local npc = hit.Parent:FindFirstChild("NPC")
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if npc and humanoid and not touched then
touched = true
humanoid:TakeDamage(10)
if humanoid.Health <= 0 then
local leaderstats = plr:FindFirstChild("leaderstats")
if leaderstats and leaderstats:FindFirstChild("Coins") then
leaderstats.Coins.Value = leaderstats.Coins.Value + 10
end
end
end
end)
game.Debris:AddItem(Hitbox, 0.1)
wait(0.2)
touched = false
db = false
end)
The reason I’d rather have GetPartInPart() is because I heard it’s more accurate, and this script doesn’t work on mobile.