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

Im having issues with a script made to change the players health can someone assist me?

Asked by 6 years ago

The script is in a normal script and in workspace

game.Players.PlayerAdded:Connect(function(Player)
    local hi = Player.Character
    local humanoid = hi:FindFirstChild("Humanoid")
    local leaderpoints = Player:FindFirstChild("leaderstats")

    humanoid.MaxHealth = leaderpoints.Durability.Value
    print(leaderpoints.Durability.Value)

end)
0
what is da problem TheluaBanana 946 — 6y
0
also what u r doing is not rly efficient TheluaBanana 946 — 6y
0
also there is plausibility that the humanoid has not loaded at the time u were defining it so u might have been asking for a nil the whole time TheluaBanana 946 — 6y
0
i think thats the issue thank you steadfast123jay 2 — 6y
View all comments (9 more)
0
Wait, nevermind. I read it wrong. *facepalm* TypicallyPacific 61 — 6y
0
lol ok TheluaBanana 946 — 6y
0
oof how do i fix this anyways ive been at it all day steadfast123jay 2 — 6y
0
Use local humanoid = hi:WaitForChild("Humanoid"). If it doesn't work comment it didn't and I'll look into it. TypicallyPacific 61 — 6y
0
Also, are you wanting it so that the humanoid's maxhealth is displayed on the leaderboard? TypicallyPacific 61 — 6y
0
no its so that the value on the leaderboard is the maxhealth also i will try what you said steadfast123jay 2 — 6y
0
If you want it to do that, in my answer below, switch durability.Value and humanoid.MaxHealth around. TypicallyPacific 61 — 6y
0
alright steadfast123jay 2 — 6y
0
any errors? GoldAngelInDisguise 297 — 6y

1 answer

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

Okay. Let's break it down. After you wait for the player to be added you're going to want to create your leaderstats. In this case, I'm going to make it a folder. Then we're going to want to create an IntValue inside of it called Durability. Then, we're going to find the character of the player. The way it works is it's going to wait for the player to load into the game, we're using Player.Name so it knows we're looking for a model with the name of your player. Then we're going to set the value of the leaderstats to the player's maxhealth.

game.Players.PlayerAdded:Connect(function(Player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Parent = Player
    leaderstats.Name = "leaderstats"
    local durability = Instance.new("IntValue")
    durability.Parent = leaderstats
    durability.Name = "Durability"
    local humanoid = game.Workspace:WaitForChild(Player.Name).Humanoid
    local leaderpoints = Player:FindFirstChild("leaderstats")

    durability.Value = humanoid.MaxHealth
    print(leaderpoints.Durability.Value)

end)

Edit:

game.Players.PlayerAdded:Connect(function(Player)
    local humanoid = game.Workspace:WaitForChild(Player.Name).Humanoid

    local leaderpoints = Player:FindFirstChild("leaderstats")

    humanoid.MaxHealth = leaderpoints.Durability.Value
    print(leaderpoints.Durability.Value)

end)
0
Sorry, I'm bad at explaining, but there you go. If it worked, please click the accept answer button. TypicallyPacific 61 — 6y
0
i already have a leaderboard with the value Durability but i will try this steadfast123jay 2 — 6y
0
You may need to tweak it a bit to fit the names of your leaderstats and where they are in the game. The only error I think you made was the humanoid part. So just put that into your script and it should work. TypicallyPacific 61 — 6y
0
You should use the edited version if you already have the leaderstats. I put it under the other code. TypicallyPacific 61 — 6y
View all comments (7 more)
0
thank you it works how do i accept the answer? steadfast123jay 2 — 6y
0
also is there a way to have it constantly update? the durability value changes and the health changes with it? steadfast123jay 2 — 6y
0
use the .Changed event of IntValue GoldAngelInDisguise 297 — 6y
0
thanks steadfast123jay 2 — 6y
0
where exactly would i put the .Changed? i tried leaderpoints.Durability.Changed:Connect(function() humanoid.MaxHealth = leaderpoints.Durability.Value but it doesnt work steadfast123jay 2 — 6y
0
Maybe instead of "game.Workspace.WaitForChild(Player.Name).Humanoid", do "(Player.Character or Player.CharacterAdded:Wait()).Humanoid", to avoid issues where some player has the same name as some other object. aschepler 135 — 6y
0
ok steadfast123jay 2 — 6y
Ad

Answer this question