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

Can someone please help me make a local script that increases max HP?

Can someone please help me make a local script that increases a player's max Hp after they buy a game pass?

I have tried for a few hours to make this local script but it won't work. this is what I have so far... local MarketplaceService = game:GetService("MarketplaceService") local Players = game:GetService("Players")

local gamePassID = 6609505 -- Change this to your game pass ID

local function onPlayerAdded(player)

local hasPass = false

-- Check if the player already owns the game pass
local success, message = pcall(function()
	hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
end)

-- If there's an error, issue a warning and exit the function
if not success then
	warn("Error while checking if player has pass: " .. tostring(message))
	return
end

if hasPass == true then
	print(player.Name .. " owns the game pass with ID " .. gamePassID)
    player.CharacterAdded:Connect(function(character)
       local humanoid = character:FindFirstChild("Humanoid")
       humanoid.MaxHealth = 500
   end)
end

end

-- Connect 'PlayerAdded' events to the 'onPlayerAdded()' function Players.PlayerAdded:Connect(onPlayerAdded)

Can someone please help me???

3 comments

0

I can help you. Add me on discord ToxicScript TV #6171

0

The reason for your error is because you need something called a "Remote Event". Running something client side only changes it for the user's device

0

Or change local script to server script. You don't need it to be in local.

1 answer

✓ Accepted answer

Your issue should be due to the Filter Enabled feature on workspace. It is a key way to prevent your game from being exploiting, but disables the ability to change non local values. I would create a RemoteEvent in ReplicatedStorage and make a function inside a Server-Side script that does the function for increasing max health.

--//SERVER SIDE// (Script)
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, humanoid, val)
     humanoid.MaxHealth = val
end)







--//CLIENT SIDE// (Local Script)
local hasPass = false

-- Check if the player already owns the game pass
local success, message = pcall(function()
    hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
end)
 
-- If there's an error, issue a warning and exit the function
if not success then
    warn("Error while checking if player has pass: " .. tostring(message))
    return
end
 
if hasPass == true then
    print(player.Name .. " owns the game pass with ID " .. gamePassID)
    player.CharacterAdded:Connect(function(character)
       local humanoid = character:FindFirstChild("Humanoid")
       game.ReplicatedStorage.RemoteEvent:FireServer(humanoid, 500)
   end)
end

Something like this should work.

1 comment

0

Easier just change the local script into server script.

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