Proximity Prompt not working

Hello,
The problem I’ve been running into is that I can’t seem to get this Proximity Prompt to work.

The way it’s supposed to work is so that when the player is low on health, they can hold “E” and regenerate the health back.

CODE:

local Part = script.Parent
local Prompt = Part.ProximityPrompt
--
local Values = workspace.Values
local HealingValue = Values.Healing
--
Prompt.PromptButtonHoldBegan:Connect(function(player)
	--
	HealingValue.Value = true
	local Character = player.Character
	local Humanoid = Character:FindFirstChild("Humanoid")
	--
	if Humanoid.Health ~= 100 then
		--
		while Humanoid.Health ~= 100 do
			--
			wait(1)
			if HealingValue.Value == true then
				--
				Humanoid.Health = Humanoid.Health + 4
				--
			elseif HealingValue.Value == false then
				break
			end	
			--
		end
	else
		--
	end	
end)
--
Prompt.PromptButtonHoldEnded:Connect(function(player)
	--
	HealingValue.Value = false
	--
end)

Cant you just add a Hold Duration and do this?

Prompt.Triggered:Connect(function(p)
local Chr = p.Character
local Hmd = Character:FindFirstChild("Humanoid")
if Hmd.Health < Hum.MaxHealth then

Humanoid.Health = Humanoid.Health + 4

else

warn("Already At Max Health!")

end

end)

That’s a great idea, thank you so much!

@xft2008
Hold Up, i think i fixed your script:

local IsHolding = false

script.Parent.PromptButtonHoldBegan:Connect(function(p)
	local Chr = p.Character
	local hmd = Chr:FindFirstChildOfClass("Humanoid")
	IsHolding = true
	
script.Parent.PromptButtonHoldEnded:Connect(function(p)
		IsHolding = false
	end)
	while IsHolding == true do
		wait(1)
		if hmd.Health < hmd.MaxHealth then
			hmd.Health += 4
		else
			warn("Already Full")
		end
	end
	
	
end)

PS: Thank you for my 80th Solution

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.