Being able to pick up medkit only if hp <100

so i want to make player being able to pick up the medkit only if his hp is <100 but i have no idea how to

Model = script.Parent
Trigger = Model:WaitForChild("Medikit")
Sound = Trigger:WaitForChild("Sound")
Config = Model:WaitForChild("Configuration")
HealthAdd = Config:WaitForChild("Health")
WaitTime = Config:WaitForChild("RegenTime")
Ready = true

function onTouched(MKit)
	local Humanoid = MKit.Parent:FindFirstChild("Humanoid")
	if Humanoid ~= nil then
		if Ready then
			Ready = false
			Sound:Play()
			Humanoid.Health = Humanoid.Health + HealthAdd.Value

			Trigger.Transparency = 1

			wait(WaitTime.Value)

			Trigger.Transparency = 0

			Ready = true
		end
	end
end

Trigger.Touched:connect(onTouched)

while true do
	Trigger.CFrame = Trigger.CFrame * CFrame.fromEulerAnglesXYZ(0, 0.01, 0)
	wait()
end
Model = script.Parent
Trigger = Model:WaitForChild("Medikit")
Sound = Trigger:WaitForChild("Sound")
Config = Model:WaitForChild("Configuration")
HealthAdd = Config:WaitForChild("Health")
WaitTime = Config:WaitForChild("RegenTime")
Ready = true

function onTouched(MKit)
	local Humanoid = MKit.Parent:FindFirstChild("Humanoid")
	if Humanoid ~= nil then
                 if Humanoid.Health < 100 then
			if Ready then
				Ready = false
				Sound:Play()
				Humanoid.Health = Humanoid.Health + HealthAdd.Value
	
				Trigger.Transparency = 1
	
				wait(WaitTime.Value)
	
				Trigger.Transparency = 0
	
				Ready = true
			end
end
	end
end

Trigger.Touched:connect(onTouched)

while true do
	Trigger.CFrame = Trigger.CFrame * CFrame.fromEulerAnglesXYZ(0, 0.01, 0)
	wait()
end
1 Like

well im trying to use it but nothing happens, no matter how much hp i have

how are yoou changing the hp? Make sure its being chnaged on the server.

1 Like

Very simple: put the healing sequence in a if loop, and use Humanoid.Health < 100. This is what @Harrystylesicoo17287 did. But I think it’s better to understand than just copy-pasting a script.

1 Like

i completely forgot about changing to server, very thanks it works now

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