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

Tool is not updating damage value when players damage value is changed?

Asked by 5 years ago

Okay, so I've been trying to figure this one out for the past 3 days.

For some context, I created a Gui inventory for the player that lets him equip armor that change his stats (melee, def etc..) I also created a stats Gui that lets the player see the bonus stats he got from the current armor equipped. When armor is equipped it updates the players damage total (dmgt.Value in script below) by adding normal damage and bonus damage values. This all works I tested it and the change can be seen in the stats Gui and in the values while the game is running in studio.

Now for my problem. When I equip some armor and hit my dummy with my tool the damage total is not being updated. I tried many different things including using a refresh function inside the Tool.Handle.Touched function, I tried placing my variables outside the functions but nothing seems to work. This script is located inside the Tool. You can see I'm trying to update dmgt.Value on line [68] which does nothing either.

When I level up through a script in ServerScriptService the normal damage value change is registered but the damage Bonus Value remains the default so maybe it has something to do with my Armor Gui's local script that is changing my player's stat values? But then why does my stat Gui detect the change and display the correct numbers but not the script in my Tool?

Tool = script.Parent

local touchenabled = true
local swinging = false
local en = true
local animnumber = 1
local timer = tick()



Tool.Activated:Connect(function()
    if en == false then return end
    en = false

    if tick()-timer > 3 then
        animnumber = 1
    end

    timer = tick()
    local char = Tool.Parent
    local hum = char.Humanoid
    local anim = hum:LoadAnimation(script.Parent["Animation"..animnumber]) -- Animation1, Animation2 and Animation 3
    anim:Play()
    swinging = true
    touchenabled = true
    wait(0.4)
    swinging = false
    animnumber = animnumber + 1

    if animnumber >= 5 then   -- if number of animations is greater then 5 reset to first anim
        animnumber = 1
        wait()
    end

    en = true

end)

Tool.Handle.Touched:Connect(function(hit)
    if not swinging then return end
    if touchenabled == false then return end
    touchenabled = false

    if hit and hit.Parent:findFirstChild("HitBox") and hit.Parent:FindFirstChild("Parry").Value == false then      -- checks for HitBox target and not parrying 
        touchenabled = false

        local char = Tool.Parent
        local playerhum = char:FindFirstChild("Humanoid")
        local PlayersService = game:GetService("Players")
        local player = PlayersService:GetPlayerFromCharacter(Tool.Parent)
        local ms = player.PlayerGui:FindFirstChild("Masterstats")
        local dmgt = ms:FindFirstChild("DmgT")

        print("old damage total..."..dmgt.Value)

        local playerposition = char.HumanoidRootPart.CFrame.LookVector


        local rootpart = hit.Parent:FindFirstChild("HumanoidRootPart")

        local position = Instance.new("BodyVelocity", rootpart)
        position.MaxForce = Vector3.new(9999999,9999999,9999999)
        position.P = 0
        position.Velocity = playerposition * 25


        --here
        dmgt.Value = ms:FindFirstChild("Dmg").Value + ms:FindFirstChild("DmgB").Value 

        hit.Parent:findFirstChild("Humanoid"):TakeDamage(dmgt.Value)

        print("new damage total..."..dmgt.Value) 

        game.Debris:AddItem(position, 0.5)  
        return
    end
end)

Answer this question