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

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

Asked by 5 years ago

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???

0
I can help you. Add me on discord ToxicScript TV #6171 RBLXNogin 187 — 5y
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 RBLXNogin 187 — 5y
0
Or change local script to server script. You don't need it to be in local. OnaKat 444 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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.

0
Easier just change the local script into server script. OnaKat 444 — 5y
Ad

Answer this question