I have created a x2 Health Gamepass Script in SeverScriptStorage and it seems not to be working.
The only function it has to do is when the player is added and when he dies that it checks if they have the gamepass. If they do then they have 200 health if they don’t they have 100. But when they have the gamepass it does not give 200 health. But it does print the stament.
local gamepassID = 19864014
local marketplaceService = game:GetService('MarketplaceService')
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Char)
if marketplaceService:UserOwnsGamePassAsync(Player.UserId, gamepassID) then
Char.Humanoid.Health = 200
print("HasPass")
else
Char.Humanoid.Health = 100
end
end)
end)
1 Like
you can’t get localplayer in server script.
2 Likes
This is how you do it
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Char)
if marketplaceService:UserOwnsGamePassAsync(Player.UserId, gamepassID) then
Char.Humanoid.Health = 200
else
Char.Humanoid.Health = 100
end
end)
end)
2 Likes
A while later and this script is not working.
It does not give the player 200 health if they have the game pass.
local gamepassID = 19864014
local marketplaceService = game:GetService('MarketplaceService')
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Char)
if marketplaceService:UserOwnsGamePassAsync(Player.UserId, gamepassID) then
Char.Humanoid.Health = 200
print("HasPass")
else
Char.Humanoid.Health = 100
end
end)
end)
It does print HasPass though and does it everytime the player dies.
1 Like
local id = 0000
game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(function(plr,ido,purchased)
if purchased and ido == id then
plr.Character.Humanoid.MaxHealth = 200
plr.Character.Humanoid.Health = 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
game.Workspace:WaitForChild(plr.Name):WairForChild("Humanoid").MaxHealth = 200
game.Workspace:WaitForChild(plr.Name):WairForChild("Humanoid").Health = 200
end
end)
end)
this will work.
you can add a solution to this post if it helps.
1 Like
I think it’s due to you not changing the max health so when you set the health over max health it will by default set to the max health value so try this:
local marketplaceService = game:GetService('MarketplaceService')
local gamepassID = 19864014
game.Players.PlayerAdded:Connect(function(Player)
marketplaceService:PromptGamePassPurchase(Player, gamepassID)
Player.CharacterAdded:Connect(function(Char)
if marketplaceService:UserOwnsGamePassAsync(Player.UserId, gamepassID) then
Char.Humanoid.MaxHealth = 200
Char.Humanoid.Health = 200
print("HasPass")
else
Char.Humanoid.MaxHealth = 100
Char.Humanoid.Health = 100
end
end)
end)
This Will Work. Tell me if it doesn’t I tested it myself. Make sure you remember to mark as solution if it helped!
5 Likes