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

why is clicking a button not changing the players max health?

Asked by 4 years ago
01Cash = script.Parent.Parent.Parent.Parent.Parent.leaderstats.Coins
02mcost = script.Parent.Cost.Value
03function onClick()
04    if Cash.Value >= mcost then
05 
06        Cash.Value = Cash.Value - mcost
07        game.Players.LocalPlayer.Character.Humanoid.MaxHealth = 150
08    end
09    end
10 
11script.Parent.MouseButton1Click:connect(onClick)

it works with subtracting the amount of cash it cost but it's not changing the maxhealth to 150

1 answer

Log in to vote
0
Answered by 4 years ago

You can try doing this script:

01local Cash = script.Parent.Parent.Parent.Parent.Parent.leaderstats.Coins
02local mcost = script.Parent.Cost
03local plr = game.Players.LocalPlayer
04 
05function onClick()
06    if Cash.Value >= mcost.Value then
07        Cash.Value = Cash.Value - mcost.Value
08        local hum = plr.Character:FindFirstChild("Humanoid")
09        hum.MaxHealth = 150
10    end
11end
12 
13script.Parent.MouseButton1Click:connect(onClick)

Having the Value of an object in a variable won't work. Also try to correctly indent your script, it makes more easier to read, understand and avoids causing errors.

0
thank you my friend made the script for a sword shop so I just copied and pasted it for a armor shop I would've done otherwise XxrockatackxX -1 — 4y
Ad

Answer this question