Weird bug with NPC Dialogue System?

I’m trying to make a dialogue NPC system. What’s the problem? If you race reroll twice, the 2nd time will take 2x, and it will keep multiplying. It’s the same for never mind. If you press it but then press yes, for some weird reason it just doubles the money, taking 2x more.

NPC Code:

local ProximityUI = script.Parent
local Cost = 10000

ProximityUI.Triggered:Connect(function(Player)
	if Player.Character.Configuration["Encountered NPC"].Value == false then
		if Player.leaderstats.Cash.Value >= 10000 then
			Player.Character.Configuration["Encountered NPC"].Value = true
			Player.PlayerGui.TextSystem.Frame:TweenPosition(UDim2.new(0.499, 0,0.86, 0),Enum.EasingDirection.Out, Enum.EasingStyle.Back, 0.4, true)
			Player.PlayerGui.TextSystem.Frame.Title.Text = script.Parent.Parent.Parent.Name
			Player.PlayerGui.TextSystem.Frame.Text.Text = "I see you have business to do."
			wait (3)
			Player.PlayerGui.TextSystem.Frame:TweenPosition(UDim2.new(0.499, 0,1.103, 0),Enum.EasingDirection.Out, Enum.EasingStyle.Back, 0.4, true)
			wait (0.5)
			Player.PlayerGui.TextSystem.Frame:TweenPosition(UDim2.new(0.499, 0,0.86, 0),Enum.EasingDirection.Out, Enum.EasingStyle.Back, 0.4, true)
			Player.PlayerGui.TextSystem.Frame.Text.Text = "Would you like to purchase “Race Reroll” for 100,000 Beli?"
			wait (1.5)
			Player.PlayerGui.TextSystem.Frame.ButtonOne.Visible = true
			Player.PlayerGui.TextSystem.Frame.ButtonOne.Text = "Yes"
			Player.PlayerGui.TextSystem.Frame.ButtonTwo.Visible = true
			Player.PlayerGui.TextSystem.Frame.ButtonTwo.Text = "Nevermind."
			local buy = script.buy:Clone()
			local nevermind = script.nevermind:Clone()
			buy.Parent = Player.PlayerGui.TextSystem.Frame.ButtonOne
			nevermind.Parent = Player.PlayerGui.TextSystem.Frame.ButtonTwo
			nevermind.Enabled = true
			buy.Enabled = true
		else
			Player.Character.Configuration["Encountered NPC"].Value = true
			Player.PlayerGui.TextSystem.Frame:TweenPosition(UDim2.new(0.499, 0,0.86, 0),Enum.EasingDirection.Out, Enum.EasingStyle.Back, 0.4, true)
			Player.PlayerGui.TextSystem.Frame.Title.Text = script.Parent.Parent.Parent.Name
			Player.PlayerGui.TextSystem.Frame.Text.Text = "I'm busy right now."
			wait (3)
			Player.PlayerGui.TextSystem.Frame:TweenPosition(UDim2.new(0.499, 0,1.103, 0),Enum.EasingDirection.Out, Enum.EasingStyle.Back, 0.4, true)
			Player.Character.Configuration["Encountered NPC"].Value = false
		end
	else
		print("Nuh uh uh")
	end
end)

Buy Script

local Player = script.Parent.Parent.Parent.Parent.Parent

Player.PlayerGui.TextSystem.Frame.ButtonOne.MouseButton1Click:Connect(function()
	Player.leaderstats.Cash.Value -= 10000
	Player.Loadout.Race.Value = "None"
	Player.PlayerGui.TextSystem.Frame.ButtonOne.Visible = false
	Player.PlayerGui.TextSystem.Frame.ButtonTwo.Visible = false
	Player.PlayerGui.TextSystem.Frame:TweenPosition(UDim2.new(0.499, 0,1.103, 0),Enum.EasingDirection.Out, Enum.EasingStyle.Back, 0.4, true)
	Player.Character.Configuration["Encountered NPC"].Value = false
	Player.Character.Humanoid.Health = 0
	script:Destroy()
end)

Nevermind Script

local Player = script.Parent.Parent.Parent.Parent.Parent

Player.PlayerGui.TextSystem.Frame.ButtonTwo.MouseButton1Click:Connect(function()
	Player.PlayerGui.TextSystem.Frame.ButtonOne.Visible = false
	Player.PlayerGui.TextSystem.Frame.ButtonTwo.Visible = false
	Player.PlayerGui.TextSystem.Frame:TweenPosition(UDim2.new(0.499, 0,1.103, 0),Enum.EasingDirection.Out, Enum.EasingStyle.Back, 0.4, true)
	Player.Character.Configuration["Encountered NPC"].Value = false
	script:Destroy()
end)

Any help will be appericated.
I’ve tried debounces but it didnt work.

Caught the culprit. It was because whenever you pressed “Nevermind” it wouldn’t delete the scripts, Lol!

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