I need Help with my script

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()

end)

Thank you if you solve it!

workspace.DistributedGameTime sounds good to get the elapsed time.
so, what to do, is get a difference between the time you spawned and now.
image

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)
1 Like

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)
1 Like

Ok. Im testing if both scripts actually work. Thank you!

Connect with lowercase c is deprecated, use Connect instead of connect.

Both of the scripts are not working. Im not that of a script guy. The only thing is that the code is in a screengui button

have you changed a first line of code? If it was yes, I didn’t made it right. :sad:

Hold on i messed something up.

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

It still spawns but i want to make a spam protection of 20 seconds. So if a player is spamming it then the vehicle is spawning after 20 seconds.

@Death_Defiance script should work perfectly for that

Could you post your code so we can try and figure out what’s going on, because it should be working.

Also take a picture of the Output so we can see if there are any errors that are coming up

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!

- ```lua
- your code
- ```

without the dashes (-)

:clone() and :Clone() doesn’t make a difference with both it still spawns.

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)

@Death_Defiance edit

You never actually specify what’s not working,

what happens to wait(20)?
does it bypass the countdown? or what?

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)

Since wait(20) is above the main function when you click it will stop the wait and jump to function which fires when you click

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

Yeah worked like i said in my last reply.