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

how to make the variable wait for one child at multiple times?

Asked by
Ali_MTR 30
3 years ago
Edited 3 years ago
local rock = script.Parent:WaitForChild("newRock") -- help me with this line



function onTouched(hit)
    local humanoid =hit.Parent:FindFirstChildWhichIsA("Humanoid")
    if humanoid ~= nil then
        print(humanoid)
        humanoid:TakeDamage(100)
    end
end

rock.Touched:Connect(onTouched)


the newrock is a clone and i want the rock variable to wait for the another clones, any help?

" the cloning script "

local rock = script.Parent.Part

local function copyRock()
    local newRock = rock:Clone()
    newRock.Name = "newRock"
    newRock.Anchored = false
    newRock.Parent = script.Parent
    wait(5)
    newRock:Destroy()
end




while true do
    wait(1)
    copyRock()
end
0
Is it giving you any errors? Amanda314159 291 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

I'm not sure if this will work or not, but it's worth a try.

local rockSpawned = false
local rock = script.Parent.newRock

while rockSpawned == false do
    if rock then
        rockSpawned = true
    end
    wait(0.1)
end

I believe this would make the script be stuck in a loop until "newRock" is cloned

0
Replace the top line with this ^^ Amanda314159 291 — 3y
Ad

Answer this question