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

Remote Event adding health doesn't add up on actual game but works on play studio?

Asked by 5 years ago
Edited 5 years ago

Local Script

player = game.Players.LocalPlayer

function update()
    local Str = player.Stats.Strength.Value
    local Agi = player.Stats.Agility.Value
    local Int = player.Stats.Intelligence.Value
    local Def = player.Stats.Defense.Value
    local Vit = player.Stats.Vitality.Value
    local Dex = player.Stats.Dexterity.Value
    local Damage = 0
    local Speed = 0
    local Critical = 0
    local CriticalDamage = 0
    local weapon

    for j,k in pairs(player.Equip:GetChildren()) do
        if k.itemType.Value == "Weapon" then
            Damage = k.itemDamage.Value
            Speed = k.itemSpeed.Value
            Critical = k.itemCritical.Value
            CriticalDamage = k.itemCritDamage.Value
            weapon = k
            script.Parent.Parent.Information.ATKDMG.Text = "ATKDMG: " .. tostring(Damage)
            script.Parent.Parent.Information.CRITCHANCE.Text = "Critical %: " .. tostring(Critical) .. "%"
            script.Parent.Parent.Information.CRITDMG.Text = "Critical DMG: " .. tostring(CriticalDamage)
        end
    end

    if weapon == nil then
        Damage = 0
        Speed = 0
        Critical = 0
        CriticalDamage = 0
        script.Parent.Parent.Information.ATKDMG.Text = "ATKDMG: " .. tostring(Damage)
    end
    script.Parent.Parent.Information.ATKDMG.Text = "ATKDMG: " .. tostring(Damage)
    script.Parent.Parent.Information.CRITCHANCE.Text = "Critical %: " .. tostring(Critical) .. "%"
    script.Parent.Parent.Information.CRITDMG.Text = "Critical DMG: " .. tostring(CriticalDamage)
    script.Parent.Parent.Information.HP.Text = "HP: " .. tostring(player.Character.Humanoid.MaxHealth)
    script.Parent.Parent.Information.ATKSpeed.Text = "ATKSpeed: " .. tostring(Speed)
    script.Parent.Parent.Information.SprintSpeed.Text = "Sprint Speed: " .. tostring(player.Stats.Agility.Value+26)
    script.Parent.Parent.Information.MP.Text = "MP: " .. tostring((player.Stats.Intelligence.Value*4)+100)
    script.Parent.Parent.Information.damageResistance.Text = "DMG Resist%: " .. tostring(player.Stats.Defense.Value/5) .. "%"
    script.Parent.Parent.Information.Stamina.Text = "Stamina: " .. tostring(player.PlayerGui.mainUI.statHolder.staminaHolder.staminaBar.MaxStamina.Value)
    script.Parent.Parent.Information.CRITCHANCE.Text = "Critical %: " .. tostring(Critical) .. "%"
    script.Parent.Parent.Information.CRITDMG.Text = "Critical DMG: " .. tostring(CriticalDamage)
    script.Parent.Parent.Information.Evasion.Text = "Evasion%: " .. tostring(player.Stats.Dexterity.Value/5) .. "%"
end

player.CharacterAdded:Connect(function()
    game.ReplicatedStorage.RemoteEvents.CharacterAdded:FireServer(player)
    update()
end)
player.Equip.ChildAdded:Connect(function()
    game.ReplicatedStorage.RemoteEvents.StatChange:FireServer("Strength")
    update()
end)
player.Equip.ChildRemoved:Connect(function()
    game.ReplicatedStorage.RemoteEvents.StatChange:FireServer("Strength")
    update()
end)
player.Stats.Strength.Changed:Connect(function()
    game.ReplicatedStorage.RemoteEvents.StatChange:FireServer("Strength")
    update()
end)
player.Stats.Agility.Changed:Connect(function()
    game.ReplicatedStorage.RemoteEvents.StatChange:FireServer("Agility")
    update()
end)
player.Stats.Intelligence.Changed:Connect(function()
    game.ReplicatedStorage.RemoteEvents.StatChange:FireServer("Intelligence")
    update()
end)
player.Stats.Defense.Changed:Connect(function()
    game.ReplicatedStorage.RemoteEvents.StatChange:FireServer("Defense")
    update()
end)
player.Stats.Vitality.Changed:Connect(function()
    game.ReplicatedStorage.RemoteEvents.StatChange:FireServer("Vitality")
    update()
end)
player.Stats.Dexterity.Changed:Connect(function()
    game.ReplicatedStorage.RemoteEvents.StatChange:FireServer("Dexterity")
    update()
end)

Server Script/s

game.ReplicatedStorage.RemoteEvents.StatChange.OnServerEvent:connect(function(player, x)
        --Health--
    if x == "Strength" then
        player.Character.Humanoid.MaxHealth = player.Character.Humanoid.MaxHealth+2
    end
    print("Lmao")
    if x == "Agility" then
    end
    if x == "Intelligence" then
    end
    if x == "Defense" then
    end
    if x == "Vitality" then
        player.Character.Humanoid.MaxHealth = player.Character.Humanoid.MaxHealth+4
    end
    if x == "Dexterity" then
    end
end)

. . .

game.ReplicatedStorage.RemoteEvents.CharacterAdded.OnServerEvent:connect(function(player, x)
        local Str = player.Stats.Strength.Value
        local Agi = player.Stats.Agility.Value
        local Int = player.Stats.Intelligence.Value
        local Def = player.Stats.Defense.Value
        local Vit = player.Stats.Vitality.Value
        local Dex = player.Stats.Dexterity.Value
    player.Character.Humanoid.MaxHealth = player.Character.Humanoid.MaxHealth+(2*Str)+(4*Vit)
    player.Character.Humanoid.Health = player.Character.Humanoid.MaxHealth
end)

I want it to add +2 health every strength point and +4 health every vitality point and make it save when character dies. It works on studio but doesn't add up(messes up) in actual game with characteradded not working and statchange messing up

Answer this question