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

A wait until function?(still needs help)

Asked by 6 years ago
Edited 6 years ago

So I have a script where a coin gives you one coin then destroys. Is there any way you can use something like a wait until function to do wait until part1 is destroyed then let the person be able to collect part2?

0
You might be able to use ChildRemoved ? User#5423 17 — 6y
0
yea I just want a script that will wait until part1 dies. Then you can collect part2 ootheboss 32 — 6y

2 answers

Log in to vote
0
Answered by
tantec 305 Moderation Voter
6 years ago

Ok, erm so what I'm going to say is gonna sound stupid in a way but it'll work.

So in order to do this you do:

while true do
if game.Workspace:FindFirstChild("part1") == nil then
game.Workspace.part2.Touched:connect(function()
[put whatever code you wanted here]
end)
break
end
wait()
end
0
Also if you already have a script for the .Touched function, you can just make that script undisabled after it finds that Part1 is nil tantec 305 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

I did this

while true do
if game.Workspace:FindFirstChild("part1") == nil then
game.Workspace.part2.Touched:connect(function()
script.Parent.Touched:connect(function(part)
    if game.Players:findFirstChild(part.Parent.Name) then
        local plr = game.Players:findFirstChild(part.Parent.Name)
        plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + 1
    end
end)
local debounce = true
script.Parent.Touched:connect(function(part)
    if debounce then
        debounce = false
        if game.Players:findFirstChild(part.Parent.Name) then
            local plr = game.Players:findFirstChild(part.Parent.Name)
            plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value
+1
            script.Parent:destroy()
        end
    end
end)
end)
break
end
wait()
end

I don't know how to fix it

Answer this question