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

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

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

✓ Accepted answer

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.

1 comment

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

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