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
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