Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I on touch, only an item will clone every second?

Asked by
Or2no 30
5 years ago
Edited 5 years ago

Sorry for the silly title, anyways:

I want to clone one item every second if a player touches an object, but with this script, the object is cloned like crazy.

local spawner = game.Workspace.ToothpasteSpawner
local detector = script.Parent
local ball = game.ServerStorage.DeathBall

local function spawnBall (part)
    local humanoid = part.Parent:FindFirstChild("Humanoid")
        if humanoid then
        local ballClone = ball:Clone()
        wait(1)
        ballClone.Parent = game.Workspace
        ballClone.Position = spawner.Position
        wait(1)
    end
end

detector.Touched:Connect(spawnBall)

1 answer

Log in to vote
0
Answered by
oreoollie 649 Moderation Voter
5 years ago
Edited 5 years ago

Simply add a debounce. Here's your code with the debounce inserted.

local spawner = game.Workspace.ToothpasteSpawner
local detector = script.Parent
local ball = game.ServerStorage.DeathBall

local db=false

local function spawnBall (part)
    local humanoid = part.Parent:FindFirstChild("Humanoid")
    if humanoid and not db then
        db = true
        local ballClone = ball:Clone()
        ballClone.Parent = game.Workspace
        ballClone.Position = spawner.Position
        wait(1)
        db =false
    end
end

detector.Touched:Connect(spawnBall)

If I answer solved your problem please remember to accept it. It helps me out a lot!

Ad

Answer this question