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

How to clone an individual part of the same into the workspace ten times?

Asked by 5 years ago
Edited 5 years ago

I am making a script that creates a shockwave and then creates spikes in the location of the shockwave. However, I can only seem to manage one spike, much less 20. I think the problem is that by declaring a variable with :clone() in it, it will only use that one clones instance as the value, so I tried cloning it outside of the variable, but to no avail.

game.ReplicatedStorage.EarthStomp.OnServerEvent:Connect(function(player)
local char = game.Players[player.Name].Character
    local hum = char.Humanoid
    local root = char.HumanoidRootPart
    local ar = Instance.new("Part")
    local ten = true
    ar.BrickColor = BrickColor.new("Bright green")
    ar.Anchored = true
    ar.CanCollide = false
    ar.Material = Enum.Material.Neon
    ar.Transparency = 0
    ar.Shape = Enum.PartType.Cylinder
    ar.Size = Vector3.new(0.01,1,1)
    ar.CFrame = player.Character["Left Leg"].CFrame + Vector3.new(0.01,0,0)
    ar.Orientation = Vector3.new(0, 0, 90)
    ar.Parent = workspace
    game.Debris:AddItem(ar,10)
    local tween = game:GetService("TweenService")
    local tweenInfo = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)
    local tweenProperty = {Size = Vector3.new(0.01,150,150);Transparency = 1}
    local tweenRun = tween:Create(ar,tweenInfo,tweenProperty)
    tweenRun:Play()
    wait(0.1)



 for i = 1,10 do
        local earthSpike = game:GetService("ServerStorage").Spike:Clone()
    earthSpike.Anchored = true
    earthSpike.CanCollide = false
    earthSpike.Parent = workspace
    earthSpike.CFrame = ar.CFrame * CFrame.new(0,math.random(-40,40),math.random(-40,40))
    while true do
    earthSpike.Orientation = Vector3.new(0,0,0)
    wait(0.1)
    end
    end

earthSpike.Touched:connect(function(hit)
local ehum = hit.Parent:findFirstChild("Humanoid") or hit.Parent.Parent:findFirstChild("Humanoid")
    earthSpike.BrickColor = hit.BrickColor
    if ehum and ehum ~= hum then
    if not ten then return end
    ten = false
    ehum:TakeDamage(20)
elseif hit.Parent == char then
return nil
elseif hit.Anchored  == true and hit.CanCollide == true then
wait(4)
ten = true
end
end)
end)

Problem Code:

for i = 1,10 do
        local earthSpike = game:GetService("ServerStorage").Spike:Clone()
    earthSpike.Anchored = true
    earthSpike.CanCollide = false
    earthSpike.Parent = workspace
    earthSpike.CFrame = ar.CFrame * CFrame.new(0,math.random(-40,40),math.random(-40,40))
    while true do
    earthSpike.Orientation = Vector3.new(0,0,0)
    wait(0.1)
    end
    end

1 answer

Log in to vote
0
Answered by 5 years ago

When you clone something you only get one instance. Like for example if you want to have 10 of those spikes you would have to clone it 10 times.

So what you can do is just clone it in your for loop:

for i=1, 10 do
    local earthSpike = game:GetService("ServerStorage").Spike:Clone()
    --properties here
end

this way you will get 10 of those spikes instead of just one

0
Im afraid this didn't work, it only spawned one spike. DominousSyndicate 41 — 5y
0
can you show how you did it because maybe you forgot to also parent inside the for loop g1o2r3d4a5n6 350 — 5y
0
K i added the problem script, but now a new problem has arisen, the game pauses to debug now when i run the script DominousSyndicate 41 — 5y
0
ok found a reason. Only 1 clones because you put infinite loop inside of the for loop. What you can do is put the infinite loop(if you really need it) outside of this for loop and then change Orientation of all those spikes at the same time also through a for loop inside of that infinite loop g1o2r3d4a5n6 350 — 5y
Ad

Answer this question