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

why does it copy the script soo many times?

Asked by 4 years ago
01script.Parent.Touched:Connect(function(hit)
02    if hit.Parent:FindFirstChild("Humanoid") then
03        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
04        local descendants = player.Character:GetDescendants()
05        if player ~= nil then
06            for index, descendant in pairs(descendants) do
07                if descendant:IsA("BasePart") and ("Decal") and descendant ~= player.Character.HumanoidRootPart then
08                    descendant.Transparency = 1
09                end
10            end
11            local scriptt = game.ReplicatedStorage.Scrapt:Clone()
12            scriptt.Parent = player.Character
13            wait(11)
14            scriptt:Destroy()
15            for index, descendant in pairs(descendants) do
View all 22 lines...

so basically when i hit a part i want it to copy a script but it copys it alot of times and ruining the actual mecanique so idk wat to do

1
add a debounce MarcTheRubixQb 153 — 4y

1 answer

Log in to vote
2
Answered by 4 years ago

You need a debounce. The character keeps touching the part over and over again, so you need to keep that from happening, there are a couple ways to go about this.

One touch This method will only allow the first person to touch it, then not anybody else.

The script beginning should look like this:

1debounce = true
2 
3script.Parent.Touched:Connect(function(hit)
4    if hit.Parent:FindFirstChild("Humanoid") and debounce == true then
5    debounce = false

Touch then wait This method will allow somebody to touch it, then after x seconds they can touch it again.

1debounce = true
2 
3script.Parent.Touched:Connect(function(hit)
4    if hit.Parent:FindFirstChild("Humanoid") and debounce == true then
5    debounce = false
6    --All the code goes here
7    wait(5)
8    debounce = true
9--All the ends

Hope this helped!

Ad

Answer this question