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?
COMMUNITY QUESTION
A wait until function?(still needs help)
2 answers
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
1 comment
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
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
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
You might be able to use ChildRemoved ?
yea I just want a script that will wait until part1 dies. Then you can collect part2