Help With A X2 HP Gamepass

I have a gamepass and it works, but you still only start with 100 hp

Summary

local Player = game.Players.LocalPlayer

if game:GetService(“MarketplaceService”):UserOwnsGamePassAsync(Player.userId, 13141338) then

game.Workspace[Player.Name]:WaitForChild(“Humanoid”).MaxHealth = 200

else

game.Workspace[Player.Name]:WaitForChild(“Humanoid”).MaxHealth = 100

end

I think i need a healscript when they spawn?

1 Like

Can you please format your code so we dont have to read it hardly?

it is basically just if they have gamepass maxhealth gets set to 200 else it gets set to 100

game.Workspace[Player.Name]:WaitForChild(“Humanoid”).MaxHealth = 200
game.Workspace[Player.Name]:WaitForChild(“Humanoid”).Health = 200

thanks. will it disable damage if i put it in a script or is there a function that runs a script whenever they spawn?

I am new to scripting so sorry if i make no sense.

game.Players.ChildAdded:Connect(function(Player)
local DoubleHealthGamepass = game:GetService(“MarketplaceService”):UserOwnsGamePassAsync(Player.userId, 13141338)
Player.ChildAdded:connect(function(Character)
– Code
end)
end)

Do your MaxHealth sets on the Server, not the client. It will not apply if the Client sets it, the client can not set its health.

will it work in a normal script in workspace or should it be in somewhere else?

also will it work every time they respawn?

Put your Server scripts in ServerScriptService. Yes, that function will give you the Character every time they spawn.

when i try it says that fartgas88_999 is not a valid member of workspace

You should NOT do game.Workspace[player.Name], here’s the thing, display names are coming to roblox AND the player character has the name as the player display name, not their username. If you wanna reference a player’s character, you should do player.Character
And Never find a player character by searching it’s name on the workspace. Please!

Do

game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:connect(function(chr)
– Tanana na
End)
End)

And then you can reference the player’s character via the variable CHR

From what I’ve seen on the code you gave, I think you are using a localscript to apply special stats for a player that buys your gamepass.

You shouldn’t do this because, first, running this on localscript will only run on the client not on the server (To explain: Client gets the 200 HP but the server, and other players can see it only 100 HP), Second, Yes the 200HP works on you but when your character starts to get damage it will go back to 100 or less because the damage is came from the server.

Heres what you gonna do:

  • Create a normal Script in the ServerScriptService

And paste this script:

local MPS = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local gamepassID = 00000000

Players.PlayerAdded:Connect(function(thePlayer)
    thePlayer.CharacterAdded:Connect(function(playerCharacter)
        if MPS:UserOwnsGamePassAsync(thePlayer.UserId, gamepassID) then
                if playerCharacter:FindFirstChild("Humanoid") then
                   playerCharacter.Humanoid.MaxHealth = 200
                   playerCharacter.Humanoid.Health = 200
               end
        end
    end)
end)

If I got some error please inform me.

It works! thanks for helping me!

1 Like