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 3 years ago
Cash = script.Parent.Parent.Parent.Parent.Parent.leaderstats.Coins
mcost = script.Parent.Cost.Value
function onClick()
    if Cash.Value >= mcost then

        Cash.Value = Cash.Value - mcost
        game.Players.LocalPlayer.Character.Humanoid.MaxHealth = 150
    end
    end

script.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 3 years ago

You can try doing this script:

local Cash = script.Parent.Parent.Parent.Parent.Parent.leaderstats.Coins
local mcost = script.Parent.Cost
local plr = game.Players.LocalPlayer

function onClick()
    if Cash.Value >= mcost.Value then
        Cash.Value = Cash.Value - mcost.Value
        local hum = plr.Character:FindFirstChild("Humanoid")
        hum.MaxHealth = 150
    end
end

script.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 — 3y
Ad

Answer this question