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

How to apply leaderstat as a health value of player?

Asked by 4 years ago

I checked out this script from someone on this website 3 years ago but it doesn't seem to work:

local plr = game.Players.LocalPlayer; local stats = plr:WaitForChild("leaderstats");

stats.BodyTempering.Changed:connect(function(change) local hum = plr.Character:FindFirstChild("Humanoid"); hum.MaxHealth = change+1; --Change health hum.Health = change+1; end)

I have a leaderstat BodyTempering inside Localplayer.Player.Leaderstats and I'm trying to change the value of the MaxHealth and Health to BodyTempering+1 (Because it begins at 0). If anyone can help I would be very greatful. The script has no known errors and humanoid is working fine. BTW I also don't know where to place the script because I started a couple of weeks ago.

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

What you did is used LocalPlayer in a server script. Something that would work is this:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)    
    player.CharacterAdded:Connect(function(character)
        local leaderstats = Instance.new("Folder")
        leaderstats.Name = "leaderstats"
        leaderstats.Parent = player

        local playerHealth = Instance.new("IntValue")
        playerHealth.Name = "Health"
        playerHealth.Value = character:WaitForChild("Humanoid").Health
        playerHealth.Parent = leaderstats

    character:WaitForChild("Humanoid"):GetPropertyChangedSignal("Health"):Connect(function()
            playerHealth.Value = character:WaitForChild("Humanoid").Health
        end)
    end)
end)
0
Sorry about the indenting being weird, it just copy and pasted that way. youtubemasterWOW 2741 — 4y
0
I already have the leaderstat created with a save ability so how do i call upon it? scorpionbloodking 2 — 4y
0
what do you mean by call upon it? youtubemasterWOW 2741 — 4y
0
For example game.players.localplayer.leaderstats.bodytempering.value scorpionbloodking 2 — 4y
0
i'm not sure what you mean by BodyTempering. Is it a value you made? youtubemasterWOW 2741 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

I think that this should work idk:

game.Players.PlayerAdded:connect(function(player)
    local leader = Instance.new("Folder", player)
    leader.Name = "leaderstats"

    local Health = Instance.new("IntValue", leader)
    Health.Name = "Health"

    Health.Value = game.Players.LocalPlayer.Humanoid.Health.Value

end)
0
Do you know where I should put it though? scorpionbloodking 2 — 4y
0
Server script service or workspace which ever you prefer DaggerSaber 14 — 4y
0
LocalPlayer is not accessible to the server, and I assume you are using a server script so therefore the script would error. You could use "player.Humanoid.Health". The parameter 'player' is the same as LocalPlayer, but for server scripts. youtubemasterWOW 2741 — 4y

Answer this question