So I’m using a BridgeNet module for my game, but I don’t understand why it’s spamming the remote events even though it has cooldowns.
Script:
function GameHandler.ActionRequest(Player, Action, Parameters)
local Profile = DataHandler:GetProfile(Player)
if Action == "Click" then
if not PlayerCooldowns[Player.UserId]["ClickCooldown"] then
PlayerCooldowns[Player.UserId]["ClickCooldown"] = true
local rebirthMultiplier = 1 + (Player.Stats.Rebirths.Value * 0.1)
local amount
local boost = Player.Boosts:FindFirstChild("x2 Clicks")
if boost and boost.Value > 0 then
amount = 1 * GetPetMultiplier(Player, "ClicksMultiplier") * rebirthMultiplier * (1 + Player.Upgrades.ClickMultiplier.Value * 0.1) * Player.Stats.WorldBoost.Value * 2
else
amount = 1 * GetPetMultiplier(Player, "ClicksMultiplier") * rebirthMultiplier * (1 + Player.Upgrades.ClickMultiplier.Value * 0.1) * Player.Stats.WorldBoost.Value
end
Player.Stats.Clicks.Value += amount
Player.Stats.TotalClicks.Value += amount
Profile.Data.Stats.Clicks += amount
Profile.Data.Stats.TotalClicks += amount
if Player.Settings.DisablePopups.Value == false then
ActionRequest:FireTo(Player,"Popup", {"rbxassetid://12535732597", amount})
end
task.wait(0.2)
PlayerCooldowns[Player.UserId]["ClickCooldown"] = false
end
elseif Action == "Rebirth" then
if not PlayerCooldowns[Player.UserId]["RebirthCooldown"] then
PlayerCooldowns[Player.UserId]["RebirthCooldown"] = true
local Cost = Player.Stats.Rebirths.Value * ItemsHandler.Rebirths[Parameters[1]].Cost + 100 * ItemsHandler.Rebirths[Parameters[1]].Amount * 2
if Profile.Data.Stats.Clicks >= Cost then
local boost = Player.Boosts:FindFirstChild("x2 Astrals")
local amount
if boost and boost.Value > 0 then
amount = ItemsHandler.Rebirths[Parameters[1]].Amount * GetPetMultiplier(Player, "AstralMultiplier") * (1 + Player.Upgrades.AstralMultiplier.Value * 0.1) * 10 * 2
else
amount = ItemsHandler.Rebirths[Parameters[1]].Amount * GetPetMultiplier(Player, "AstralMultiplier") * (1 + Player.Upgrades.AstralMultiplier.Value * 0.1) * 10
end
Player.Stats.Clicks.Value -= Cost
Player.Stats.Astrals.Value += amount
Player.Stats.TotalAstrals.Value += amount
Player.Stats.Rebirths.Value += ItemsHandler.Rebirths[Parameters[1]].Amount
Profile.Data.Stats.Clicks -= Cost
Profile.Data.Stats.Astrals += amount
Profile.Data.Stats.TotalAstrals += amount
Profile.Data.Stats.Rebirths += ItemsHandler.Rebirths[Parameters[1]].Amount
if Player.Settings.DisablePopups.Value == false then
ActionRequest:FireTo(Player, "Popup", {"rbxassetid://12535746756", ItemsHandler.Rebirths[Parameters[1]].Amount})
ActionRequest:FireTo(Player, "Popup", {"rbxassetid://12535765352", amount})
end
task.wait(0.5)
PlayerCooldowns[Player.UserId]["RebirthCooldown"] = false
end
end
elseif Action == "CraftPet" then
if not PlayerCooldowns[Player.UserId]["CraftCooldown"] then
PlayerCooldowns[Player.UserId]["CraftCooldown"] = true
if Player.Stats.Astrals.Value >= Parameters[2] then
Player.Stats.Astrals.Value -= Parameters[2]
Profile.Data.Stats.Astrals -= Parameters[2]
local PetRandom = math.random(1, 100)
if PetRandom <= Parameters[1] then
local ClonePetTemplate = script.Parent.PetTemplate:Clone()
ClonePetTemplate.Name = Parameters[4][1][2]
ClonePetTemplate.PetID.Value = GenerateGUID()
ClonePetTemplate.Type.Value = Parameters[3]
ClonePetTemplate.Parent = Player.Pets
local PetTable = {
PetName = Parameters[4][1][2],
Equipped = false,
Locked = false,
TotalXP = 0,
Type = Parameters[3]
}
Profile.Data.Pets[ClonePetTemplate.PetID.Value] = PetTable
ActionRequest:FireTo(Player, "Notification", {"✅ Success!"})
end
if PetRandom >= Parameters[1] then
ActionRequest:FireTo(Player, "Notification", {"Failed! 😥"})
end
for _,v in pairs(Parameters[4]) do
local Folder = GetFolderFromPetID(Player, v[1])
if Folder ~= nil then
Profile.Data.Pets[v[1]] = nil
PetFollowHandler:RemovePet(Player, v[1])
Folder.Equipped.Value = false
Folder:Destroy()
end
end
end
task.wait(1)
PlayerCooldowns[Player.UserId]["CraftCooldown"] = false
end
elseif Action == "Upgrade" then
if not PlayerCooldowns[Player.UserId]["UpgradeCooldown"] then
PlayerCooldowns[Player.UserId]["UpgradeCooldown"] = true
local stat = Profile.Data.Upgrades[Parameters[1]]
local type_of_stat = type(stat)
local Cost
if type_of_stat == "boolean" then
Cost = Parameters[2]
if stat == true then
return
end
elseif type_of_stat == "number" then
--Cost = Parameters[2] * (Player.Stats[Parameters[1]].Value + 1) ^ 2
Cost = Parameters[2] * (Player.Upgrades[Parameters[1]].Value + 1)
if stat >= Parameters[3] then
return
end
end
if Profile.Data.Stats.Astrals >= Cost then
Profile.Data.Stats.Astrals -= Cost
Player.Stats.Astrals.Value -= Cost
local statToUpdate = Parameters[1]
if type(Profile.Data.Upgrades[statToUpdate]) == "boolean" then
Profile.Data.Upgrades[statToUpdate] = true
elseif type(Profile.Data.Upgrades[statToUpdate]) == "number" then
Profile.Data.Upgrades[statToUpdate] = Profile.Data.Upgrades[statToUpdate] + 1
end
Player.Upgrades[statToUpdate].Value = Profile.Data.Upgrades[statToUpdate]
task.wait(0.5)
PlayerCooldowns[Player.UserId]["UpgradeCooldown"] = false
end
end
elseif Action == "AutoDelete" then
local Rarity = Parameters[1]
local SetValue = Parameters[2]
Player.AutoDelete[Rarity].Value = SetValue
Profile.Data.AutoDelete[Rarity] = SetValue
elseif Action == "Settings" then
local Setting = Parameters[1]
local SetValue = Parameters[2]
Player.Settings[Setting].Value = SetValue
Profile.Data.Settings[Setting] = SetValue
end
end
Server Script:
task.wait()
-- [[ Services ]]
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
-- [[ Variables ]]
local GameAssets = ReplicatedStorage.GameAssets
local Modules = GameAssets.Modules
local Events = GameAssets.Events
local ServerModules = ServerStorage.ServerModules
local BridgeNet = require(Modules.BridgeNet)
local ActionRequest = BridgeNet.CreateBridge("ActionRequest")
local BuyPortalRequest = BridgeNet.CreateBridge("BuyPortalRequest")
-- [[ Modules ]]
local EggHandler = require(ServerModules.EggHandler)
local CodeHandler = require(ServerModules.CodeHandler)
local DataHandler = require(ServerModules.DataHandler)
local GameHandler = require(ServerModules.GameHandler)
local GlobalLeaderboardHandler = require(ServerModules.GlobalLeaderboard)
local PetHandler = require(ServerModules.PetHandler)
local PortalHandler = require(ServerModules.PortalHandler)
local ProductHandler = require(ServerModules.ProductHandler)
-- [[ Initialize ]]
EggHandler:Int()
CodeHandler:Int()
DataHandler:Int()
GameHandler:Init()
GlobalLeaderboardHandler:Int()
PortalHandler:Int()
ProductHandler:Int()
ActionRequest:Connect(function(Player, Action, Parameters)
GameHandler.ActionRequest(Player, Action, Parameters)
end)
BuyPortalRequest:Connect(function(Player, PortalName)
PortalHandler.PurchasePortal(Player, PortalName)
end)
Events.PetActionRequest.OnServerInvoke = function(Player, Action, Parameters)
return PetHandler.ActionRequest(Player, Action, Parameters)
end
Events.OpenEgg.OnServerInvoke = function(Player, EggName, Action)
return EggHandler.OpenEgg(Player, EggName, Action)
end
I hope you can help me.