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

I need help doing this health gamepass script im new to coding can somewho help me ?

i need help doing this health gamepass its supposed to do 200 max health but it does not work

local Marketplaceservice = game:GetService("MarketplaceService") local Players = game:GetService("Players")

local gamepassid = 18430436

local button = script.Parent

local function promptpurchase() local player = Players.LocalPlayer local haspass = false

local success, message = pcall (function()
	haspass = Marketplaceservice:UserOwnsGamePassAsync(player.UserId, gamepassid)
end)

if not success then 
	warn ("Error while checking if player had gamepass")
	return
end

if haspass 
	then button.Text = "already owned"
else
	Marketplaceservice:PromptGamePassPurchase(player, gamepassid)
end

end

button.MouseButton1Click:Connect(promptpurchase)


local Marketplaceservice = game:GetService("MarketplaceService") local Players = game:GetService("Players")

local gamepassid = 18430436

local function givegamepassPerks (player) if player.character then local humanoid = player.Character:waitforChild ("humanoid") humanoid.Health *= 200 end player.Characteradded:connect(function(character) local humanoid = player.Character:waitforChild ("humanoid") humanoid.Health *= 200 end) end

local function onplayeradded (player) local hasPass = false

local success, message = pcall (function()
	hasPass = Marketplaceservice:UserOwnsGamePassAsync(player.UserId, gamepassid)
end)

if not success then 
	warn ("Error while checking if player had gamepass")
	return
end

if hasPass then 
	givegamepassPerks(player)
end

end

Marketplaceservice.PromptGamePassPurchaseFinished:connect (function(player, passid, wasPurchased)

end)

Players.playeradded:Connect(onplayeradded)

it does not work and im not sure why

2 answers

im new to this site and though you may could help me so sorry if the script shown is a little weird

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Wait()
local success, message = pcall (function()
    hasPass = Marketplaceservice:UserOwnsGamePassAsync(player.UserId, gamepassid)
end)

if not success then 
    warn ("Error while checking if player had gamepass")
    return
end

if hasPass then 
    givegamepassPerks(player)
end
end)

My guess is that you're making the health increase to fast, you'll need to wait till the character is loaded.

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