Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago

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

Log in to vote
0
Answered by 2 years ago

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

Ad
Log in to vote
0
Answered by 2 years ago
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.

Answer this question