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

How to make only one part to drop instead of hundreds?

Asked by 5 years ago

Hi ,

So, I want a part to drop only once when ever something touches it, but the part gets dropped 100 times. And I am using a Ontouched() function. Here is the code:

function onTouched(hit)
    local partDrop = script.Parent
    local part = Instance.new("Part",partDrop)
    part.CFrame = partDrop.CFrame - Vector3.new(0,1.4,-1)
    part.FormFactor = "Custom"
    part.Size=Vector3.new(0.75,0.75,0.75)
    part.Material = "Neon"
    part.TopSurface = "Smooth"
    part.BottomSurface = "Smooth"
    part.CanCollide = true
    print("Dropped!")
    game.Debris:AddItem(part,math.random(2,5))
    wait(6)
end

script.Parent.Touched:Connect(onTouched)

Thanks for Helping

2 answers

Log in to vote
0
Answered by 5 years ago

Touched fires insanely, especially if the player stands on it. I recommend adding a debounce to most scripts that use an event.Here is the script with a debounce.

local debounce=false--declaring
function onTouched(hit)
if  debounce==false then 
debounce=true--making it true
    local partDrop = script.Parent
    local part = Instance.new("Part",partDrop)
    part.CFrame = partDrop.CFrame - Vector3.new(0,1.4,-1)
    part.FormFactor = "Custom"
    part.Size=Vector3.new(0.75,0.75,0.75)
    part.Material = "Neon"
    part.TopSurface = "Smooth"
    part.BottomSurface = "Smooth"
    part.CanCollide = true
    print("Dropped!")
    game.Debris:AddItem(part,math.random(2,5))
    wait(6)
debounce=false--making it false

end

script.Parent.Touched:Connect(onTouched)
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
canSpawn = true
print("Ready!")

function onTouched(hit)
    if canSpawn then
        canSpawn = false
        local partDrop = script.Parent
        local part = Instance.new("Part",partDrop)
        part.CFrame = partDrop.CFrame - Vector3.new(0,1.4,-1)
        part.FormFactor = "Custom"
        part.Size=Vector3.new(0.75,0.75,0.75)
        part.Material = "Neon"
        part.TopSurface = "Smooth"
        part.BottomSurface = "Smooth"
        part.CanCollide = true
        print("Dropped!")
        game.Debris:AddItem(part,math.random(2,5))
        wait(4)
        canSpawn = true
        print("Ready!")
    end
end

script.Parent.Touched:Connect(onTouched)

Hope this helped you

0
Thanks and does this work if the parent (part) is not collideable? awesomemode14 68 — 5y
0
I think it does develop_d 53 — 5y

Answer this question