I’m having troubles with my moneydrop. Mainly, everytime I drop, It keeps multiplying.
Example:
If I drop 1000$
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.
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)