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

4 comments
Im afraid this didn't work, it only spawned one spike.
can you show how you did it because maybe you forgot to also parent inside the for loop
K i added the problem script, but now a new problem has arisen, the game pauses to debug now when i run the script
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