Moneydrop Glitch

I’m having troubles with my moneydrop. Mainly, everytime I drop, It keeps multiplying.

Example:

If I drop 1000$

image

It drops 2000$

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Events = ReplicatedStorage:WaitForChild("Events")
local LocalPlayer = Players.LocalPlayer
local Mouse = LocalPlayer:GetMouse()
local Money = LocalPlayer:WaitForChild("Money")
local Frame = script.Parent
local DropAmountBox = Frame:WaitForChild("DropAmount")
local DropButton = Frame:WaitForChild("DropButton")
local DropMoney = Events:WaitForChild("DropMoney")
local CloseButton = Frame:WaitForChild("CloseButton")
local ErrorMessage = Events:WaitForChild("ErrorMessage")

CloseButton.MouseButton1Click:Connect(function()
	Frame.Visible = false
end)

DropMoney.OnClientEvent:Connect(function()
	Frame.Visible = true
	DropButton.MouseButton1Click:Connect(function()
		local DropAmount = tonumber(DropAmountBox.Text)
		if typeof(DropAmount) == "number" then
			Frame.Visible = false
			DropMoney:FireServer(DropAmount)
		else
			warn("DropMoney is not a valid number!")
			ErrorMessage:FireServer("Error","It is not a valid number!")
			Frame.Visible = false
		end
	end)
end)

LocalPlayer.PlayerGui.ScreenGui.MoneyDropFrame.DropButton.MouseButton1Click:Connect(function()
	local DropAmount = tonumber(LocalPlayer.PlayerGui.ScreenGui.MoneyDropFrame.DropAmount.Text)
	if typeof(DropAmount) == "number" then
		LocalPlayer.PlayerGui.ScreenGui.MoneyDropFrame.Visible = false
		DropMoney:FireServer(tonumber(DropAmount))
	else
		warn("DropMoney is not a valid number!")
	end
end)


DropMoney.OnClientEvent:Connect(function()
	LocalPlayer.PlayerGui.ScreenGui.MoneyDropFrame.Visible = true
end)

From what I can see, you’re creating two connections for the same button. One nested inside the OnClientEvent of DropMoney, and another below.
You shouldn’t need the connection inside of OnClientEvent. It’s essentially firing DropMoney to the server twice, hence dropping double the money.

That’s just from a quick observation though.

I’ve seen that too, but I’m confused as to how’d I fix it?

Remove the connection inside of OnClientEvent and keep the one under it; then try test again.

Like this?

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Events = ReplicatedStorage:WaitForChild("Events")
local LocalPlayer = Players.LocalPlayer
local Mouse = LocalPlayer:GetMouse()
local Money = LocalPlayer:WaitForChild("Money")
local Frame = script.Parent
local DropAmountBox = Frame:WaitForChild("DropAmount")
local DropButton = Frame:WaitForChild("DropButton")
local DropMoney = Events:WaitForChild("DropMoney")
local CloseButton = Frame:WaitForChild("CloseButton")
local ErrorMessage = Events:WaitForChild("ErrorMessage")

CloseButton.MouseButton1Click:Connect(function()
	Frame.Visible = false
end)


DropButton.MouseButton1Click:Connect(function()
	local DropAmount = tonumber(DropAmountBox.Text)
	if typeof(DropAmount) == "number" then
		Frame.Visible = false
		DropMoney:FireServer(DropAmount)
	else
		warn("DropMoney is not a valid number!")
		ErrorMessage:FireServer("Error","It is not a valid number!")
		Frame.Visible = false
	end
end)

LocalPlayer.PlayerGui.ScreenGui.MoneyDropFrame.DropButton.MouseButton1Click:Connect(function()
	local DropAmount = tonumber(LocalPlayer.PlayerGui.ScreenGui.MoneyDropFrame.DropAmount.Text)
	if typeof(DropAmount) == "number" then
		LocalPlayer.PlayerGui.ScreenGui.MoneyDropFrame.Visible = false
		DropMoney:FireServer(tonumber(DropAmount))
	else
		warn("DropMoney is not a valid number!")
	end
end)


DropMoney.OnClientEvent:Connect(function()
	LocalPlayer.PlayerGui.ScreenGui.MoneyDropFrame.Visible = true
end)

Remove this part entirely. It seems to be doing the exact same thing as the connection underneath.

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