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

Multiple clones on 1 touch???

Asked by 5 years ago
Edited 5 years ago

This is what's happening https://gyazo.com/c87afac7a2c901e4acfaea31d6f60a5a

this is my script

p = script.Parent
function off (hit)
    local e = hit.Parent
    local humanoid = e:FindFirstChildWhichIsA("Humanoid")
    if ( humanoid ) then
    b = game.ServerStorage.a:Clone()
    b.Parent = game.Workspace
    end

end

p.Touched:Connect(off)

I only want it to clone once when I'm touching the the scripts parent and only to clone another if I stopped touching the part and retouched it.

What am I doing wrong?

0
use debounce.. greatneil80 2647 — 5y
0
Could you give me an example? veileno 7 — 5y
0
sure..! local a = true if a == true then a = false else a = true greatneil80 2647 — 5y
0
also, that might be because multiple parts of a player are touching the part theking48989987 2147 — 5y

1 answer

Log in to vote
1
Answered by
Optikk 499 Donator Moderation Voter
5 years ago

You can debounce. A quick example of debouncing with the Part.Touched event:

local debounce = false
local somePart = workspace.Part

somePart.Touched:Connect(function(hit)
    if not debounce then

        -- now we just set debounce to true
        -- this prevents the code below from being executed too quickly
        debounce = true

        -- put your code after that
        print(hit.Name .. ' touched a part!')

        -- then we wait (in this example, one second)
        -- and we set debounce back to false
        wait(1)
        debounce = false
    end
end)

What does this do? Basically, by setting debounce to true, we are preventing the code from being executed too fast. The wait at the end is the delay until the code within the if block can be executed again.

0
a more accurate way: if debounce == true then return end DeceptiveCaster 3761 — 5y
0
"if not debounce then" is not guaranteed to work, trust me DeceptiveCaster 3761 — 5y
0
MCAndRobloxUnited thanks for telling me, but can you elaborate? Optikk 499 — 5y
0
ninja'd OfcPedroo 396 — 5y
Ad

Answer this question