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

Local script dosent save max health upgrades?

Asked by 1 year ago

So i made a script that is supposed to upgrade your max health but i tried making it so it saves even after your death But the script didnt work Here is the script:

local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
local respawnTime = 3

player.CharacterAdded:Connect(function(char)
    local humanoid = char:WaitForChild("Humanoid")
    if humanoid then
        humanoid.Died:Connect(function()
            wait(respawnTime)
            player.Character.Humanoid.MaxHealth = leaderstats.MaxHealth.Value
            player.Character.Humanoid.Health = leaderstats.MaxHealth.Value
        end)
        end
end)
0
Also just a tip: you don't need to check if 'humanoid' exists if you're using WaitForChild. ScriptGuider 5640 — 1y
0
Im trying to get the maxhealth from the leaderstats doe ImNotAN00b_0kay 31 — 1y

1 answer

Log in to vote
0
Answered by 1 year ago
Edited 1 year ago

Well, a few things here.

1. You shouldn't be changing humanoid properties that should be replicated to other players in a localscript. This should be done server-side (in a server script), or through a localscript that fires a server-side event (using remote events).

2. I don't believe you need to use a Died event on the humanoid in order to re-assign the max health. You should just be able to wait for the character to respawn, then change the max health.

Here is an implementation of this inside of a server script:

local Players = game:GetService("Players");

-- some default max health you want to assign
local DEFAULT_MAX_HEALTH = 500;

local onPlayerAdded = function(newPlayer)
    newPlayer.CharacterAdded:Connect(function(char)
        local humanoid = char:WaitForChild("Humanoid")

        -- update the humanoid's health/max health
        humanoid.MaxHealth = DEFAULT_MAX_HEALTH;
        humanoid.Health = humanoid.MaxHealth;
    end))
end

Players.PlayerAdded:Connect(onPlayerAdded);

Let me know if you have any questions

0
Where do i put script ImNotAN00b_0kay 31 — 1y
Ad

Answer this question