Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to apply leaderstat as a health value of player?

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

✓ Accepted answer

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)

5 comments

0

Sorry about the indenting being weird, it just copy and pasted that way.

0

I already have the leaderstat created with a save ability so how do i call upon it?

0

what do you mean by call upon it?

0

For example game.players.localplayer.leaderstats.bodytempering.value

0

i'm not sure what you mean by BodyTempering. Is it a value you made?

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)

3 comments

0

Do you know where I should put it though?

0

Server script service or workspace which ever you prefer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.