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