Im trying to make a combat script, and it works fine in studio… but in game it one shots everyone… and i have no clue why
i tried to fix it, but after an hour of stressing over it i decided to come here and see if anyone could possibly point out any flaws in my code
local module = {}
local anims = {"rbxassetid://4503665409";
"rbxassetid://04806050820";
}
local animation = script.Animation
function module.Punch(player)
local yaboi = {}
local myboi = {}
local char = player.Character
local leftArm = char:FindFirstChild("Left Arm")
local rightArm = char:FindFirstChild("Right Arm")
local data = player.Data
animation.AnimationId = anims[math.random(1,#anims)]
local animPlayer = char:FindFirstChild("Humanoid"):LoadAnimation(animation)
animPlayer:Play()
data.XP.Value = data.XP.Value + math.random(1,20)
if animation.AnimationId == anims[1] then
leftArm.Touched:Connect(function(hit)
if yaboi[player] ~= true then
yaboi[player] = false
if hit.Parent:FindFirstChild("Humanoid") then
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum.Parent.Name ~= player.Name then
wait(1)
hum:TakeDamage(data.Strength.Value * 2 + math.random(1,20))
local tago = Instance.new('ObjectValue',hit.Parent.Humanoid)
tago.Name = 'creator'
tago.Value = player
game.Debris:AddItem(tago,.25)
wait(1)
yaboi[player] = true
end
end
end
end)
else
if animation.AnimationId == anims[2] then
rightArm.Touched:Connect(function(hit)
if myboi[player] ~= true then
myboi[player] = false
if hit.Parent:FindFirstChild("Humanoid") then
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum.Parent.Name ~= player.Name then
hum:TakeDamage(data.Strength.Value * 2 + math.random(1,20))
local tag = Instance.new('ObjectValue',hit.Parent.Humanoid)
tag.Name = 'creator'
tag.Value = player
game.Debris:AddItem(tag,.25)
wait(1)
myboi[player] = true
end
end
end
end)
end
end
end
return module