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

Part not cloning into correct Object?

Asked by
Donut792 216 Moderation Voter
5 years ago

ok so in my game i have it where it will make a "bluebarrel" and when it does it is supposed to put a "speedup" inside of it which works fine but it wont clone into the one that spawned it will clone into the one that is already in workspace,ignore the chance and powerupchance variables they are for later use

script:

workspace.ChildAdded:Connect(function(obj)
    if obj:IsA("UnionOperation") then
        if obj.Name == "BlueBarrel" then
            print("BlueBarrel Appeared")
            local Chance = math.random(1,5)
            local PowerupChance = math.random(1,5)
            local clone1 = game.ReplicatedStorage.SpeedUp:Clone()
            clone1.Parent = workspace
            clone1.Position = obj.Position
        end
    end
end)
0
If SpeedUp is a part, set the CFrame instead of the Position. Vector3 has collision detection, so attempting to position a part with Position will make sure it doesn't clip through anything. User#24403 69 — 5y
0
it is supposed to clip through items for a effect as if it was actually inside the barrel Donut792 216 — 5y
0
cancollide is off on speedup but not barrel Donut792 216 — 5y

1 answer

Log in to vote
0
Answered by
zValerian 108
5 years ago

You are putting the speedup inside the workspace instead of the barrel. Here is the correct script:

workspace.ChildAdded:Connect(function(obj)
    if obj:IsA("UnionOperation") then
        if obj.Name == "BlueBarrel" then
            print("BlueBarrel Appeared")
            local Chance = math.random(1,5)
            local PowerupChance = math.random(1,5)
            local clone1 = game.ReplicatedStorage.SpeedUp:Clone()
            clone1.Parent = obj -- obj, not workspace
            clone1.Position = obj.Position
        end
    end
end)
0
i forgot to mention that the barrel gets :Destroy()'ed so if i parent it to the barrel it will also be destroyed, tho i did try changing it to obj instead of workspace but it still did the same thing Donut792 216 — 5y
Ad

Answer this question