So I have a script that saves under the enemy when he lands stones, but they always appear behind him. I tried a bunch of values to change, but it does not affect anything.
How do I make it so that under the place where the enemy landed, the stones appear?
Here’s my script that spells out the stones. This is a local script, and it’s part of my larger script that is responsible for the stones:
local function crater(data)
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
local currentTime = tick()
local craterRaycastResult
repeat
craterRaycastResult = workspace:Raycast(data.Target.PrimaryPart.Position, data.Direction, params)
wait()
until craterRaycastResult ~= nil or tick() - currentTime > 5
if craterRaycastResult then
for i = 0, 14 do
local part = Instance.new("Part", workspace.Fx)
part.Size = Vector3.new(4, math.random(10, 20)/10, math.random(10, 20)/10)
part.Anchored = true
part.CFrame = CFrame.new(craterRaycastResult.Position, craterRaycastResult.Position + craterRaycastResult.Normal)
part.CFrame = part.CFrame * CFrame.Angles(math.rad(90), math.rad(i * 360/14), 0) * CFrame.new(0, 0, -4 * 2) * CFrame.Angles(math.rad(35), 0, 0)
part.CanQuery = false
part.CanCollide = false
part.CanTouch = false
local result = workspace:Raycast(part.Position + craterRaycastResult.Normal * 40, craterRaycastResult.Normal * -100, params)
print(result)
if result then
part.Position = result.Position
part.Material = result.Material
part.Color = result.Instance.Color
else
part:Destroy()
end
part.Position = part.Position + craterRaycastResult.Normal * -4
ts:Create(part, TweenInfo.new(.2, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out, 0, false, 0), {Position = part.Position + craterRaycastResult.Normal * 4}):Play()
spawn(function()
game.Debris:AddItem(part, 4)
wait(3)
ts:Create(part, TweenInfo.new(.5, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out, 0, false, 0), {Position = part.Position + craterRaycastResult.Normal * -4}):Play()
end)
if i % 3 < 2 and result then
local rubble = part:Clone()
rubble.Size = Vector3.new(math.random(10, 20)/20, math.random(10, 20)/20, math.random(10, 20)/20)
rubble.Position = result.Position + craterRaycastResult.Normal * 4
rubble.Material = result.Material
rubble.Color = result.Instance.Color
rubble.Parent = workspace.Fx
rubble.Anchored = false
rubble.CanCollide = true
local bv = Instance.new("BodyVelocity", rubble)
bv.Velocity = Vector3.new(math.random(-40, 40), 30, math.random(-40, 40))
bv.MaxForce = Vector3.new(99999, 99999, 99999)
bv.Name = "Velocity"
game.Debris:AddItem(bv, .1)
game.Debris:AddItem(rubble, 4)
spawn(function()
wait(2)
ts:Create(rubble, TweenInfo.new(1, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out, 0, false, 0), {Transparency = 1}):Play()
end)
rubble.Transparency = 0
end
end
end
end
And here is the script in which I call the function, I will say right away that I intentionally left out the part where I create the event in which I call the function:
data.Action = "Crater"
data.Direction = (data.Character.PrimaryPart.CFrame.LookVector * 1 - Vector3.new(0, 2, 0)) * 1
event:FireAllClients(data)