Hi, so I’ve just ran into a problem with my client sending info to the server.
For some reason, the amount amount of players in the server equates to how many times the server is fired from the client.
Example:
Here, I dropped the money once, but it drops twice due to the client firing twice for some reason?
Client:
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")
-- Settings
local DropTaxPercentage = 0.8 -- 0.1 = 10%
CloseButton.MouseButton1Click:Connect(function()
Frame.Visible = false
end)
Frame.DropButton.MouseButton1Click:Connect(function()
local DropAmount = tonumber(Frame.DropAmount.Text)
if typeof(DropAmount) == "number" then
print("Client-Fire")
DropAmount = DropAmount * 0.8
DropAmount = math.floor(DropAmount)
Frame.Visible = false
DropMoney:FireServer(tonumber(DropAmount)) -- This is where I fire the server
else
warn("DropMoney is not a valid number!")
ErrorMessage:FireServer("Error","Not a valid number!")
end
end)
DropMoney.OnClientEvent:Connect(function()
Frame.Visible = true
end)
Server:
local Players = game:GetService("Players")
local Debris = game:GetService("Debris")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local Events = ReplicatedStorage.Events
local Tool = script.Parent
local Handle = Tool.Handle
local MoneyGui = Handle.MoneyGui
local MoneyLabel = MoneyGui.MoneyLabel
local DropMoney = Events.DropMoney
local ServerErrorMessage = Events.ServerErrorMessage
-- Settings
local MoneyLifetime = 300 -- 5 minutes
local formatNumber = (function (n)
n = tostring(n)
return n:reverse():gsub("%d%d%d", "%1,"):reverse():gsub("^,", "")
end)
Tool.Equipped:Connect(function()
local Character = Tool.Parent
local Player = Players:GetPlayerFromCharacter(Character)
local Money = Player.Money
MoneyLabel.Text = formatNumber(tostring(Money.Value)).."$"
end)
Tool.Activated:Connect(function()
local Character = Tool.Parent
local Player = Players:GetPlayerFromCharacter(Character)
local Money = Player.Money
DropMoney:FireClient(Player)
end)
DropMoney.OnServerEvent:Connect(function(Player, DropAmount)
print("Fire")
local Money = Player.Money.Value
local Character = Player.Character or Player.CharacterAdded:Wait()
local moneymodules = ServerStorage.MoneyModules
local moneybag_min = 2500
local DropAmount = math.max(0,DropAmount)
DropAmount = DropAmount
if DropAmount == 0 then
ServerErrorMessage:Fire(Player, "Error","Number cannot be negative!")
return
end
if DropAmount >= moneybag_min and Money > DropAmount and Money > 0 then
local moneyDebounce = false
-- Moneybag B)
print("moneybag", tostring(DropAmount).."$")
MoneyLabel.Text = formatNumber(Player.Money.Value)
local moneybag = moneymodules.Moneybag:Clone()
moneybag.Parent = workspace
moneybag.CFrame = Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-5)
Player.Money.Value -= DropAmount
moneybag.MoneyGui.MoneyLabel.Text = formatNumber(DropAmount).."$"
Debris:AddItem(moneybag, MoneyLifetime)
moneybag.Touched:Connect(function(hitObject)
pcall(function()
if hitObject.Parent.Humanoid and not moneyDebounce then
moneyDebounce = true
local Character = hitObject.Parent
local Player = Players:GetPlayerFromCharacter(Character)
Player.Money.Value += DropAmount
moneybag.MoneyPickup:Play()
moneybag.MoneyPickup.Ended:Wait()
moneybag:Destroy()
moneyDebounce = false
end
end)
end)
elseif DropAmount < moneybag_min and Money > DropAmount and Money > 0 then
local moneyDebounce = false
-- Money
print("money", tostring(DropAmount).."$")
local money = moneymodules.Money:Clone()
money.Parent = workspace
money.CFrame = Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-5)
Player.Money.Value -= DropAmount
money.MoneyGui.MoneyLabel.Text = formatNumber(DropAmount).."$"
Debris:AddItem(money, MoneyLifetime)
money.Touched:Connect(function(hitObject)
pcall(function()
if hitObject.Parent.Humanoid and not moneyDebounce then
moneyDebounce = true
local Character = hitObject.Parent
local Player = Players:GetPlayerFromCharacter(Character)
Player.Money.Value += DropAmount
money.MoneyPickup:Play()
money.MoneyPickup.Ended:Wait()
money:Destroy()
moneyDebounce = false
end
end)
end)
end
end)
Any help would be appreciated, thanks!