Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why doesn't my damage increase when Combat Value increases?!?

Asked by 7 years ago

basically when your attk increases your dmg is supposed to increase and do more damage to an enemyhumanoid why isn't this working?

wait(2)

Player = game.Players.LocalPlayer
P = script.Parent:WaitForChild("Animation")
char =Player.Character
RA = char["Left Arm"]
k = true
    local attk=script.Parent.Parent.Combat.Value
    local def = script.Parent.Parent.Defense.Value
    local d=(attk/def)*10+1
    local dmg=d/def
function  onDamage(Part)
    if k == true then
        k = false
        if script.Parent.Punch.Value == 4 then
        if Part.Parent:FindFirstChild("Humanoid")~= nil then    
Part.Parent.Humanoid:TakeDamage(dmg)
end
end
wait(2)
k = true    
end
end

RA.Touched:connect(onDamage)

2 answers

Log in to vote
0
Answered by 7 years ago

Explanation in chat.

wait(2)

Player = game.Players.LocalPlayer
P = script.Parent:WaitForChild("Animation")
char =Player.Character
RA = char["Left Arm"]
k = true

local attk = script.Parent.Parent.Combat
local def = script.Parent.Parent.Defense

function onDamage(Part)
    if k then -- we dont need to check for true as it will only run if true
        k = false
            if script.Parent.Punch.Value == 4 then
                if Part.Parent:FindFirstChild("Humanoid")~= nil then 
                    -- you had (attk/def)*10+1
                    -- which can be simplifyed to (attk/def)*11
                    -- then d/def
                    -- so (attk/def)*11 / def
                    Part.Parent.Humanoid:TakeDamage((attk.Value/def.Value)*11 / def.Value) -- you will need to work out the damage each time you change the combad or defence
                end
            end
    wait(2)
    k = true    
    end
end

RA.Touched:connect(onDamage)

Hope this helps, comment if you need any help.

Ad
Log in to vote
0
Answered by 7 years ago

The reason your damage isn't updating is because you only set its value ONCE in your current script (at line 11). To make sure the damage value changes, you need to set it INSIDE your function. so,

wait(2)

Player = game.Players.LocalPlayer
P = script.Parent:WaitForChild("Animation")
char =Player.Character
RA = char["Left Arm"]
k = true


function  onDamage(Part)
    if k == true then

    local attk=script.Parent.Parent.Combat.Value
    local def = script.Parent.Parent.Defense.Value
    local d=(attk/def)*10+1
    local dmg=d/def

        k = false
        if script.Parent.Punch.Value == 4 then
        if Part.Parent:FindFirstChild("Humanoid")~= nil then    
Part.Parent.Humanoid:TakeDamage(dmg)
end
end
wait(2)
k = true    
end
end

RA.Touched:connect(onDamage)

Answer this question