I have this script that spawns cars, so some exploiters keep firing this remote event that causes a lot of cars to spawn on the map, and makes the game laggy, what do I need to do? please help.
Local Script(On Gui):
local player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SpawnCarEvent = ReplicatedStorage:WaitForChild("sw")
local DeleteCarEvent = ReplicatedStorage:WaitForChild("ac")
local carName = script.Parent.Name
local SpawnCarFrame = script.Parent.Parent
script.Parent.MouseButton1Down:Connect(function()
SpawnCarFrame.Visible = false
local CurrentCar = game.Workspace:FindFirstChild(player.Name .. 'sCar')
if not CurrentCar then
SpawnCarEvent:FireServer(carName)
else
if player.Character.Humanoid.SeatPart ~= nil and player.Character.Humanoid.SeatPart:IsA("VehicleSeat") then
player.Character.Humanoid.Sit = false
end
wait()
DeleteCarEvent:FireServer(CurrentCar)
SpawnCarEvent:FireServer(carName)
end
end)
Script(ServerScriptService):
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SpawnCarEvent = ReplicatedStorage:WaitForChild("sw")
local DeleteCarEvent = ReplicatedStorage:WaitForChild("ac")
SpawnCarEvent.OnServerEvent:Connect(function(player, carName)
local Car = ServerStorage:FindFirstChild("Cars"):FindFirstChild(carName)
if Car then
local clonedCar = Car:Clone()
clonedCar.Name = player.Name .. 'sCar'
clonedCar.Parent = game.Workspace
clonedCar:MoveTo(player.Character.HumanoidRootPart.Position + player.Character.HumanoidRootPart.CFrame.LookVector * 15)
end
end)
DeleteCarEvent.OnServerEvent:Connect(function(player, Car)
if Car then
Car:Remove()
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local Car = game.Workspace:FindFirstChild(player.Name .. 'sCar')
if Car then
Car:Remove()
end
end)
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local Car = game.Workspace:FindFirstChild(player.Name .. 'sCar')
if Car then
Car:Remove()
end
end)
end)

6 comments
umm this can stop exploit from firing event alot? like they use script like : game.replicatedstorage.RemoteEvent:Fire
A way to stop exploiters from firing the event a lot is to add a server-sided cooldown.
can u make one? im new to this things.
scripting helpers is not a request website
"can u make one" yeah
aight if u can make it, im accepting ur answer!