Healing Station

Hey everyone as of right now I am trying to make a healing station so that when you interact with the proximity prompt you gain health but it drains until its unusable sort of like the dev @UmmmOkayWhat’s system in rickey rat.

– My code as of now only heals the player –

local MarketplaceService = game:GetService(“MarketplaceService”)
local Player = game.Players.LocalPlayer

script.Parent.ProximityPrompt.Triggered:connect(function(player)
if game.MarketplaceService:UserOwnsGamePassAsync(player.UserId) then
game.Players.localplayer.Humanoid.Maxhealth += 100
end
end)

First off all please format your code.
Now for the errors,

  1. You aren’t healing the player you are adding their max health instead of adding to their Health.
  2. You are looking for a Humanoid in localplayer which doesn’t exist (also it should be LocalPlayer) you need to look for it in the player’s character.
  3. You aren’t checking if the player owns the gamepass, you are calling the function with no gamepassId
  4. This needs to be a server script as Local Scripts don’t run in the workspace.

Your code with all that fixed should be:

--// Services
local MSS = game:GetService("MarketplaceService")

--// Variables
local gamepassId = 12121 -- Paste your gamepass Id there.

--// Functions
local function promptTrigger(player)
    if MSS:UserOwnsGamePassAsync(player.UserId) then
        local char = player.Character 
        char.Humanoid.Health = 100
    end
end

--// Connections
script.Parent.ProximityPrompt.Triggered:Connect(promptTrigger)
1 Like

Your code actually only messes with health on the client side which is not helpful. You should be doing this through a server script

1 Like