Medkit won't delete after usage

This medkit won’t delete after usage. The uses value increasing works but for some reason it just won’t delete even if the value goes over. I’ve tried replacing the “>=” on the 4th to last line with “==” and it doesn’t work. I’m not sure why.

local ProximityPromptService = game:GetService("ProximityPromptService")
local ProximityPrompt = script.Parent
local Sound = script.Parent.Parent.Heal
local incrementValue = 20 --can be changed to any value depending upon how much health you want to increase
local Uses = script.Parent.Parent.Uses

ProximityPrompt.Triggered:Connect(function(player)
	Sound:Play()
	workspace[player.Name].Humanoid.Health = workspace[player.Name].Humanoid.Health + incrementValue
	Uses.Value = Uses.Value + 1
	print("Health increased")

end)

if Uses.Value >= 5 then
	print("a")
	script.Parent.Parent:Destroy()
end

It’s because you only check the Uses value once, so when it goes over five, you don’t detect the value change. Try putting it after you increase the Uses value:

ProximityPrompt.Triggered:Connect(function(player)
	Sound:Play()
	workspace[player.Name].Humanoid.Health = workspace[player.Name].Humanoid.Health + incrementValue
	Uses.Value = Uses.Value + 1
	
	if Uses.Value == 5 then
		script.Parent.Parent:Destroy()
	end
end)
1 Like

On another note, use Player.Character to access a player’s character

2 Likes

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