so i wanted to create a punch hitbox that gets created everytime someone clicks, which works.
what doesnt work however, is the part itself. it detects collisions VERY inconsistently, and very rarely. i made the part flash red whenever it detected a collision, and it only detects a collision every 1/10 punches.
anything helps!!
script
local enterEvent = game.ReplicatedStorage.Going_In
local punchEvent = game.ReplicatedStorage.Punch
punchEvent.OnServerEvent:Connect(function(player)
local character = player.Character
local humanoid = character:FindFirstChild("Humanoid")
local hrp = character:FindFirstChild("HumanoidRootPart")
local leaderstats = player:WaitForChild("leaderstats")
local punches = leaderstats:WaitForChild("Punches")
local punchey_part = Instance.new("Part")
punchey_part.CanCollide = false
punchey_part.Anchored = true
punchey_part.Size = Vector3.new(4,4,4)
punchey_part.CFrame = hrp.CFrame
punchey_part.Parent = character
punchey_part.Transparency = 0
local function playAnimationFromServer(character, animation)
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
-- need to use animation object for server access
local animator = humanoid:FindFirstChildOfClass("Animator")
if animator then
local animationTrack = animator:LoadAnimation(animation)
animationTrack:Play()
return animationTrack
end
end
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://15196133419"
playAnimationFromServer(character, animation)
punchey_part.Touched:Connect(function(hit)
punchey_part.Color = Color3.new(1, 0, 0)
local debounce = true
if hit.Parent ~= punchey_part.Parent then
local human = hit.Parent:FindFirstChild("Humanoid")
local hrp = hit.Parent:FindFirstChild("HumanoidRootPart")
if human and debounce == true and hit == hrp and humanoid.Health > 0 then
human.Health -= 10
punches.Value += 1
hit.Parent:FindFirstChild("RagdollTrigger").Value = true
wait(1)
hit.Parent:FindFirstChild("RagdollTrigger").Value = false
debounce = false
end
end
end)
wait(0.1)
punchey_part:Destroy()
end)