I was told to replace my hitbox with Raycasting so I made this script that inflicts damage each time I click. Sometimes it works and other times it doesnt and I have no idea why.
This is what it looks like: Punch
You can see that even though a punch was thrown it didnt inflict damage like the other ones.
Heres the script:
ID1 = "http://www.roblox.com/Asset?ID=343805145"
ID2 = "http://www.roblox.com/Asset?ID=344655490"
ID3 = "http://www.roblox.com/Asset?ID=344667896"
AttackList = {ID1, ID2, ID3,}
local Player = game.Players.LocalPlayer
repeat wait() until game.Players.LocalPlayer.Character
local Mouse = Player:GetMouse()
local new = 1
enabled = true
Mouse.Button1Down:connect(function(key)
if not enabled then
return
end
enabled = false
local TestAttack = Instance.new("Animation")
TestAttack.AnimationId = AttackList[new]
local animTrack = Player.Character.Humanoid:LoadAnimation(TestAttack)
animTrack:Play()
local ray = Ray.new(Player.Character.Torso.Position, Vector3.new(0, 0, 10))
local part, endPoint = workspace:FindPartOnRay(ray)
if part == nil then
else if part ~= nil then
local human = part.Parent:FindFirstChild("Humanoid")
if human and (not debounce) and (human.Parent ~= Player.Character) then
debounce = true
end
end
end
wait(0.3)
enabled = true
end)
I think the problem is at lines 22-29 but I don't know what they are. Please help.

1 comment
Worst case scenario is that it might be a roblox glitch. Roblox isnt flawless :p... Maybe the raycasting just... didnt hit the npc because it glitched? just sayin'...