Why does'nt this script work

i made this 2x health script but the problem is that it only doubles the players max health and not there current health it also doesnt save and goes back to 100 health when you die how can i fix this?

-- local id = 35766079

game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(function(plr,ido,purchased)
	if purchased and ido == id then
		plr.Character.Humanoid.MaxHealth = 200
	end
end)

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:connect(function(char)
		if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(game.Players[char.Name].UserId, id) then
			char.Humanoid.MaxHealth = 200
		end
	end)
end)

i’m gonna clean up your code a bit:

local id = 35766079
local Players = game:GetService('Players')
local MPService = game:GetService('MarketplaceService')

MPService.PromptGamePassPurchaseFinished:Connect(function(plr,ido,purchased)
	if purchased and ido == id then
		local Humanoid = plr:FindFirstChildWhichIsA('Humanoid')
		if Humanoid then
			plr.Character.Humanoid.MaxHealth = 200
		end
	end
end)

Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		if MPService:UserOwnsGamePassAsync(game.Players[char.Name].UserId, id) then
			local Humanoid = plr:FindFirstChildWhichIsA('Humanoid')
			if Humanoid then
				plr.Character.Humanoid.MaxHealth = 200
			end
		end
	end)
end)

i uncommented id, made a nil check for the humanoid, and made variables for services

note that you may have to just use :WaitForChild() on the characteradded part

see if that works (:

1 Like

it doesnt seem to work

1.Try what @IConsumeCheddar wrote above.
2.When you’re only updating/setting the MaxHealth, it won’t automatically do that for the current health. Thus, you’d have to set their current hp aswell to that value.
3.To make it work for each time the player is in-game, you could either set a variable inside their player called HP and work with that[match it with the actual HP,etc]. Or, simply use CharacterAdded, but notice you’d need to use WaitForChild [for the humanoid].

made a silly mistake, i tried to look for the humanoid in the player:

local id = 35766079
local Players = game:GetService('Players')
local MPService = game:GetService('MarketplaceService')

MPService.PromptGamePassPurchaseFinished:Connect(function(plr,ido,purchased)
	if purchased and ido == id and plr.Character then
		local Humanoid = plr.Character:FindFirstChildWhichIsA('Humanoid')
		if Humanoid then
			plr.Character.Humanoid.MaxHealth = 200
		end
	end
end)

Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		if MPService:UserOwnsGamePassAsync(game.Players[char.Name].UserId, id) then
			local Humanoid = char:WaitForChild('Humanoid')
			plr.Character.Humanoid.MaxHealth = 200
			plr.Character.Humanoid.Health = 200
		end
	end)
end)

it still doesnt increase the current health

Don’t forget to put this line too -

plr.Character.Humanoid.Health = 200

[Below the MaxHealth line]

1 Like

this might be the issue ^ @IT1024

also if there are any errors in the output please share

1 Like

it works thx alot for your help
you to @Valkyrop

2 Likes