Help me fix my script

I m making a notify system where player pick up a item or earn some money it will tell you but end up with 2 bug

first , the backpack bug, the notifier notify you even though player spamming equip and unequip and heres the script

	Player.Backpack.ChildAdded:Connect(function(ItemName)
		print(ItemName)
		if not Player.Character:FindFirstChildWhichIsA("Humanoid"):UnequipTools(ItemName) then
			local Label = script.Label:Clone()
			Label.Parent = Player.PlayerGui.MenuGui.CashBalance.GetFrame
			Label.Text = "+ "..ItemName.Name

			local GetSFX = script.GetSFX:Clone()
			if not char.PrimaryPart:FindFirstChild(GetSFX.Name) then
				GetSFX.Parent = char.PrimaryPart
				GetSFX:Play()
				game.Debris:AddItem(GetSFX,2)
			end

			local invistween = game:GetService("TweenService"):Create(Label, TweenInfo.new(1), {TextTransparency = 1})
			invistween:Play()
			invistween.Completed:Connect(function()
				invistween:Play()
				invistween.Completed:Connect(function()
					Label:Destroy()
				end)
			end)
		end

	end)

Second , Notify Money Bug, no matter how much money added to player it would only show + 100 Cash

	Player.Backpack.ChildAdded:Connect(function(ItemName)
		print(ItemName)
		if not Player.Character:FindFirstChildWhichIsA("Humanoid"):UnequipTools(ItemName) then
			local Label = script.Label:Clone()
			Label.Parent = Player.PlayerGui.MenuGui.CashBalance.GetFrame
			Label.Text = "+ "..ItemName.Name

			local GetSFX = script.GetSFX:Clone()
			if not char.PrimaryPart:FindFirstChild(GetSFX.Name) then
				GetSFX.Parent = char.PrimaryPart
				GetSFX:Play()
				game.Debris:AddItem(GetSFX,2)
			end

			local invistween = game:GetService("TweenService"):Create(Label, TweenInfo.new(1), {TextTransparency = 1})
			invistween:Play()
			invistween.Completed:Connect(function()
				invistween:Play()
				invistween.Completed:Connect(function()
					Label:Destroy()
				end)
			end)
		end

	end)

I am having a hard time following along with your code. Therefore, I am just going to provide you with code demonstrating the proper events for what you are trying to do, then you can fill in the rest with what you want.

local Players = game:GetService("Players")
local StarterGui = game:GetService("StarterGui")

local Player = Players.LocalPlayer
local Backpack = Player:WaitForChild("Backpack")

local leaderstats = Player:WaitForChild("leaderstats")
local cash = leaderstats:WaitForChild("Cash")
local cashAmount = cash.Value

local notificationDebounce = {}

local function debounce(item)
	if (not table.find(notificationDebounce,item)) then
		table.insert(notificationDebounce,item)
		task.delay(5,function()
			for i, v in pairs(notificationDebounce) do
				if (v == item) then
					table.remove(notificationDebounce,i)
				end
			end
		end)
		return false
	else
		return true
	end
end

local function notification(title,text)
	StarterGui:SetCore("SendNotification", {
		Title = title,
		Text = text,
		Duration = 5
	})
end

Player.CharacterAdded:Connect(function()
	Backpack = Player:WaitForChild("Backpack")
end)

Backpack.ChildAdded:Connect(function(item)
	if (not debounce(item)) then
		notification("Item Added",item.Name.." was added to your backpack.")
	end
end)

cash.Changed:Connect(function(amount)
	local changed = (amount - cashAmount)
	if (changed > 0) then
		notification("Cash Gained","+"..changed.." was added to your balance.")
		cashAmount = amount
	end
end)

This script uses StarterGui:SetCore to create notifications. One notification is created when an item is added to the player’s backpack, and there is a five-second debounce so the same item can’t be spammed. The second notification is created when a player’s “Cash” leaderstat is changed. It uses a local variable to calculate how much the cash value has changed, and if it changed positively, a notification is displayed.

If you found this useful, please mark it as a solution so others can find the answer right away. If you have any more questions, feel free to reply and I will answer them for you.

1 Like