I’m making an ability to spawn rocks. But the problem is my rocks won’t spawn
Here’s the code:
function(player)
local chars = {}
local char = player.Character
spawn(function()
local rockystomp = game.ReplicatedStorage.CommandItems.RockyStomp:Clone()
rockystomp.Parent = char.HumanoidRootPart
rockystomp:Play()
local cframe = char.HumanoidRootPart.CFrame
local direction = cframe.LookVector
local pos = char.HumanoidRootPart.Position
local heightbetweenlegsandrootpart = (char.HumanoidRootPart.Position-(char.HumanoidRootPart.Position+Vector3.new(0,-(char.HumanoidRootPart.Size.Y/2+char["Left Leg"].Size.Y),0))).Magnitude
wait(.1)
for i=1,25 do
local rock = Instance.new("Part",game.Workspace)
rock.Name = "Rock"
rock.BrickColor = BrickColor.new("Grey")
rock.Material = Enum.Material.Pebble
rock.Size = Vector3.new(12,14,4)
rock.Anchored = true
rock.CanCollide = false
local canharm = true
local e = -(heightbetweenlegsandrootpart+((pos+Vector3.new(0,-heightbetweenlegsandrootpart,0))-Vector3.new(pos.X,game.Workspace.Baseplate.Position.Y+(game.Workspace.Baseplate.Size.Y/2),pos.Z)).Magnitude)
rock.CFrame = cframe * CFrame.new(0,e,-3-(3.2*i))
if game.Workspace:Raycast(rock.Position,(-rock.CFrame.UpVector).Unit*10) then
rock.CFrame = rock.CFrame * CFrame.new(0,-10,0) * CFrame.Angles(math.rad(math.random(-20,20)),math.rad(math.random(-20,20)),math.rad(math.random(-20,20)))
game:GetService("TweenService"):Create(rock,TweenInfo.new(.15),{Position = rock.Position+Vector3.new(0,10,0)}):Play()
rock.Touched:Connect(function(hit)
if canharm then
if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
if hit.Parent.Humanoid.Health ~= 0 then
local hitchar = hit.Parent
local hitplr = game.Players:GetPlayerFromCharacter(hitchar)
if (hitplr and hitplr.IsOnMatch.Value) or (not hitplr) then
if hitchar~= char then
if chars[hitchar] == nil then
chars[hitchar] = true
hitchar.Humanoid.Health-=10
end
end
end
end
end
end
end)
spawn(function()
wait(.5)
canharm = false
wait(5)
game:GetService("Debris"):AddItem(rock,2.5)
game:GetService("TweenService"):Create(rock,TweenInfo.new(2),{Position = rock.Position+Vector3.new(0,-15,0)}):Play()
end)
else
rock:Destroy()
end
wait(.02)
end
end)
end,
Please help me, and thank you!