0
votes

I'm trying to reward the player with exp every time they the punch a damageable object (punching bag, dummies, etc) Whenever the play punches something, it updates the exp leaderstat only once, does anyone know what i'm doing wrong?

My Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

script.Parent.Touched:Connect(function(hit)
    local Char = hit.parent
    local Hum = Char:FindFirstChild("Humanoid")
    if Hum and Char.Name ~= script.Parent.Parent.Name then
        local Indicator = require(game.ReplicatedStorage.DamageIndicator)
        local Player = script.Parent.Parent
        local LocalPlayer = game.Players:GetPlayerFromCharacter(Player)
        local Exp = LocalPlayer.leaderstats.Experience.Value
        Hum:TakeDamage(script.Dmg.Value)
        Indicator.DamageActivate(script.Dmg.Value, hit)
        Exp = Exp + 15
        LocalPlayer.PlayerGui.UI.Experience.ExpBar.Size = UDim2.new((Exp / 100) * 0, 0, 0.02, 0)
        LocalPlayer.PlayerGui.UI.Experience.ExpBackground.ExpAmt.Text = Exp.."/100"
        script.Disabled = true
    end
end)
1
Why are you disabling the script? - Kylaaa

1 Answers

0
votes

You're having the same issue as this guy.

When you create a variable based on a NumberValue's Value, you are storing a copy of the value, not a reference to it. If you want to update the value, you need to manually assign it.

local Exp = LocalPlayer.leaderstats.Experience
Exp.Value = Exp.Value + 15

local ExpGui = LocalPlayer.PlayerGui.UI.Experience
ExpGui.ExpBar.Size = UDim2.new((Exp.Value / 100) * 0, 0, 0.02, 0)
ExpGui.ExpBackground.ExpAmt.Text = tostring(Exp.Value) .. "/100"