Hello I need help with my anti car spam script. I dont know how to solve this script.
wait(20) – Countdown for Car Spawn (NOT WORKING)
script.Parent.MouseButton1Click:connect(function(GetCar)
Mod = game.ServerStorage.V1 --V1 is the Car name
clone = Mod:clone()
clone.Parent = workspace
clone:MakeJoints()
workspace.DistributedGameTime sounds good to get the elapsed time.
so, what to do, is get a difference between the time you spawned and now.
local PreviousSpawn = 0
script.Parent.MouseButton1Click:connect(function()
local GameTime = workspace.DistributedGameTime
if GameTime - PreviousSpawn >= 20 then -- If time elapsed over 20 seconds?
local Mod = game.ServerStorage.V1
local clone = Mod:clone()
clone.Parent = workspace
clone:MakeJoints()
PreviousSpawn = GameTime
end
end)
I’m assuming you want to reduce the numbers of cars that can be spawned in a set time? If so, you can use Debounce to stop a player from spawning the car if not enough time has passed since it was last spawned, debounce works like this
canSpawn = true
script.Parent.MouseButton1Click:connect(function()
if canSpawn == true then
canSpawn = false
-- run code to spawn the car
wait(10) -- How long to wait between spawning cars
canSpawn = true
end
end)
I’m not a problem fixing guy but here’s your story.
You have to wait 20 seconds After 20 seconds, then clicking the button will run the event You used :clone() and not :Clone() :clone() is deprecated You cloned, parent it to workspace and make joints of the model
but it doesnt work?
try Mod = game.ServerStorage["V1"]
instead of Mod = game.ServerStorage.V1
because number bad
BUT IF IT DOESNT WORK, CHECK AGAIN if u are in the right place
check if the name is correct
check if it is kept in serverstorage
change :clone() to :Clone()
change :connect() to :Connect()
EVERYTHING CAN BE PROBLEM, WE CAN SOLVE THIS!
As a friendly reminder, remember to use code blocks!
canSpawn = true
script.Parent.MouseButton1Click:Connect(function()
if canSpawn == true then
canSpawn = false
Mod = game.ServerStorage.V1
clone = Mod:Clone()
clone.Parent = workspace
wait(10) -- How long to wait between spawning cars
canSpawn = true
end
end)
Its working but i edited it that the car is then anchored after the spawn. Like this:
canSpawn = true
script.Parent.MouseButton1Click:connect(function()
if canSpawn == true then
canSpawn = false
Mod = game.ServerStorage.V1
clone = Mod:Clone()
clone.Parent = workspace
clone:MakeJoints() ------ You forgot that i think.
wait(10) – How long to wait between spawning cars
canSpawn = true
end
end)
Have you tried it with makejoints? Did it work? I have never used makejoints so I dont really know, you can add a weld script from toolbox by Quenty in your model which you are trying to clone