Im making a rogue game. I made a simple script that creates a hitbox for punches. The problem is that I can’t make it to not spawn at all if “hit” (other players or npc’s) is abscent.
Here’s the local script part of the punch:
--//click
script.Parent.Activated:Connect(function()
if canPunch and char:WaitForChild("movement"):WaitForChild("isSliding").Value == false and toolequipped then
canPunch = false
count = (count%#pAnims)+1
local Animation = animator:LoadAnimation(pAnims[count])
Animation:Play()
wait(0.2)
--//hitbox
local hitbox = Instance.new("Part")
hitbox.Transparency = 0.5
hitbox.Color =Color3.new(1, 0, 0)
hitbox.Anchored = false
hitbox.Parent = plr.Character
hitbox.Name = "fistHitbox"
hitbox.CFrame = CFrame.new(plr.Character:WaitForChild("HumanoidRootPart").Position)
hitbox.Size = Vector3.new(3,3,2.2)
hitbox.CanCollide = false
local weld = Instance.new("Weld")
weld.Parent = hitbox
weld.Part0 = hitbox
weld.Part1 = plr.Character:WaitForChild("HumanoidRootPart")
weld.C0 = CFrame.new(0,0,hitboxDistance)
hitbox.Touched:Connect(function(hit)
if hit and hit.Parent ~= char then
rEvent:FireServer(hit, dmg)
hitbox:Destroy()
else
hitbox:Destroy()
end
end)
wait(.6)
canPunch = true
end
end)
And here’s the server script:
game:GetService("ReplicatedStorage"):WaitForChild("RMEV"):WaitForChild("Combat").OnServerEvent:Connect(function(plr, hit, dmg)
hit.Parent.Humanoid:TakeDamage(dmg)
end)
I believe the fix is incredibly simple and I just made a dumb mistake, but I can’t fix this issue for 2 days now.
Video of the issue: