#With what do I replace WaitForChild?

1 messages · Page 1 of 1 (latest)

somber axle
#

I want this script to target every part that spawns instead of only the first part that spawned, how do I do this? The script: ```lua
coroutine.wrap(function()
local WeldConstraint1 = game.Workspace.Terrain:WaitForChild("Part").WeldConstraint
WeldConstraint1.Part1 = hitPart.Parent:WaitForChild("HumanoidRootPart")
print("It got triggered 2")
end)()

#

wouldn't it still target the first part that spawns if I looped this?

#

what do you mean by that

#

forgot to mention that this script activates whenever a new part spawns

sterile tide
#

Store generated part in a var?

#

before activating

#

@somber axle

somber axle
# sterile tide Store generated part in a var?

This is the full function: ```lua
function OnRayHit(cast, raycastResult, segmentVelocity, cosmeticBulletObject)
-- This function will be connected to the Caster's "RayHit" event.
local hitPart = raycastResult.Instance
local hitPoint = raycastResult.Position
local normal = raycastResult.Normal
print("It got triggered")
if hitPart ~= nil and hitPart.Parent ~= nil then -- Test if we hit something
local humanoid = hitPart.Parent:FindFirstChildOfClass("Humanoid") -- Is there a humanoid?
if humanoid then
humanoid:TakeDamage(10)
end
coroutine.wrap(function()
explosion(hitPoint, normal)
end)()

    coroutine.wrap(function()
        local WeldConstraint1 = game.Workspace.Terrain:WaitForChild("Part").WeldConstraint
        WeldConstraint1.Part1 = hitPart.Parent:WaitForChild("HumanoidRootPart")
        print("It got triggered 2")
    end)()


end
return true

end

#

It generates a part and puts it in game.Workspace.Terrain whenever I hit something

#

I managed to modify the script so that every spawned part gets targetted but the old parts are still being targetted

#

I want this function to only apply once to a part instead of every time it gets triggered

#

Imma post the new script in a bit