local NPC = {"NPC","NPC2"}
local player = game:GetService("Players").LocalPlayer
local plr = game:GetService("Players")
repeat wait() until workspace:FindFirstChild(player.Name) ~= nil
local char = player.Character

char.Humanoid.Changed:Connect(function()
	for i, v in pairs(workspace:GetChildren()) do
		for l, j in pairs(NPC) do
			if v.Name == j then
				local A = v.HumanoidRootPart.CFrame.p
				local B = char.HumanoidRootPart.CFrame.p
				local maxDistance = 10
				if (A-B).magnitude <= maxDistance then
					v.BillboardGui.Enabled = true
					script.CurrentNPC.Value = v.Name
					game:GetService("UserInputService").InputBegan:Connect(function(key)
						if key.KeyCode == Enum.KeyCode.E then
							player.leaderstats.Present.Value = player.leaderstats.Present.Value - 1
						end
					end)
				else
					if v.Name == script.CurrentNPC.Value then
					v.BillboardGui.Enabled = false
					end
				end
				break
			end
		end
	end
end)

When I press E once, it triples this player.leaderstats.Present.Value = player.leaderstats.Present.Value - 1 . I think it is because I use Humanoid.Changed. How do I solve this? I need help. Thank you.

6 comments

0

why not just use a debounce

0

Just tell me what you want and I'll make it for you it's easier this way...

0

^ Yeah that's how this website works.

0

Changed is slowly being deprecated, use :GetPropertyChangedSignal()

0

Changed will never be deprecated

0

If a player gets near with NPC it will show the Press E billboard gui, when the player press E then the player's cash value from the leaderstats will minus 1