Money Drop Error

So I’m making a money drop command for my upcoming game and I’ve encountered an issue.

I say the command drop/money/amount and it is only supposed to drop a single block of money. Instead it does this:

It uses a BindableEvent that upon being Fired drops the money.

My Code [COMMAND SCRIPT]:

game.Players.PlayerAdded:connect(function(plr)
for i = 1, #admins do
	plr.Chatted:Connect(function(msg)
		if msg:sub(1,11):lower() == 'drop/money/' then
			game.ReplicatedStorage.AdminDropMoney:Fire(msg:sub(12))
		end
	end)
end

end)

My Code [DROP SCRIPT]:

local event = game.ReplicatedStorage.AdminDropMoney

event.Event:connect(function(plr, amt)
local moneyModel = game.ServerStorage:WaitForChild('MoneyModel'):Clone(1)
moneyModel:WaitForChild('Price').Value = amt
moneyModel.MoneyGui.TextLabel.Text = 'Money! Pick it up before anyone else!'
moneyModel.Parent = workspace:WaitForChild('MoneyDrops')

end)
1 Like

Do you happen to have 6 admins on your list? You’re connecting a .Chatted event for each admin you have. I think what you intended for this line is to look through the admin list and find out if the player is an admin, THEN attach the .Chatted event.

3 Likes

I do indeed have 6 admins, ill work on the fix, thank you very much!

What @ExtremeBuilder15 said. You’re running a loop everytime a player joins, and connecting a chatted event for each player, even ones that already have one connected to them.

Luckily this is easily solvable simply by doing something similar to this

local Admins = {
	[1] = true
}

Players.PlayerAdded:Connect(function(p)
	if Admins[p.UserId] then
		p.Chatted:Connect(function(msg)
			--Code
		end)
	end
end)
3 Likes

Thank you! (: