Help with Extra Health

Hello,
So I’m making an extra health gamepass. But it won’t work. My humanoid health changes, but my health Gui doesn’t.

Script:

players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
	
		
		
		for _, gamepassTool in pairs(game.ReplicatedStorage.GamepassToolsA:GetChildren()) do
			if not MPS:UserOwnsGamePassAsync(player.UserId,gamepassTool.Name) then
				
				local clonedTool = gamepassTool:Clone()
				
				clonedTool.Parent = player.Backpack
				
				if clonedTool:FindFirstChild('Script') then
					clonedTool.Script.Disabled = false
				end
			end
		end
		
		local humanoid = char:WaitForChild('Humanoid')

		if not MPS:UserOwnsGamePassAsync(player.UserId,12642019) then
			humanoid.MaxHealth = 200
			humanoid.Health = 200
		end
	end)
end)

Local Script:

local player = game:GetService('Players').LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

spawn(function()
	wait(math.random(3,7))
	game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health,false)
end)



local function round(n)
	return math.floor(n + 0.5)
end


local humanoid = character:WaitForChild('Humanoid')
local red = script.Parent:WaitForChild('Red')
humanoid.HealthChanged:Connect(function(newHealth)
	if humanoid.MaxHealth == 200 then
		red.Green.HealthAmount.Text = tostring(round(newHealth))
		red.Green:TweenSize(UDim2.new(newHealth / 200,0,1,0),Enum.EasingDirection.InOut,Enum.EasingStyle.Quart,.3)
	else
		red.Green.HealthAmount.Text = tostring(round(newHealth))
		red.Green:TweenSize(UDim2.new(newHealth / 100,0,1,0),Enum.EasingDirection.InOut,Enum.EasingStyle.Quart,.3)
	end
end)

When I edit my health, it goes to the correct number, but when I own the gamepass, it doesn’t change.

1 Like

Does your Gui use the ‘changed’ event for a Int or Num Value?

My Health Gui script is the second script on my post.

This may be the problem, it says if the max health is equal to 200 blah blah blah, but if it isn’t, it is set to

red.Green.HealthAmount.Text = tostring(round(newHealth))
		red.Green:TweenSize(UDim2.new(newHealth / 100,0,1,0),Enum.EasingDirection.InOut,Enum.EasingStyle.Quart,.3)

So maybe try to fix that, and your code might function as intended.

1 Like