How to perfectly align ice spike model to ground

I’m making an ice spike move, I want to perfectly align the model to the ground, Not inside it, below it, or above it, I used howtoroblox’s tutorial for the move, but it just doesnt stick to the ground, instead the last 2 spikes are either inside the ground or above it. I also wanna make it so u cant do the move if there’s not enough space or there’s a hole in where you’re gonna do the move
Like this: image
The main thing I wanna do is perfectly put the spikes in the ground, if you’ve noticed from the picture above, there are cylinder-sphere shaped parts under the spike, it’s joined with the spike and it’s a mesh, the thing is they’re under the ground when I do the move as shown below
image
I dont know if I should seperate the circle itself and the spikes and animate them seperately.

first, what you’re doing is right. But it just need a little more fixing.
you have to create a template part first. Every part have a Position located on the middle
Then, use the raycast with a Vector3.new(0,-999,0) as a direction. When it hits. Get a Position property and set the spike position there.

It sounds weird but i’ll explain later!

1 Like

Okay, thank you.

I’ll wait :slight_smile:

You could use the Target property of the player’s mouse object and get its position along the Y axis and then spawn the ice spike model using that.

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local rs = game:GetService("ReplicatedStorage")
local isRemote = rs:WaitForChild("IceSpikesRemote")

mouse.Button1Down:Connect(function()
	local target = mouse.Target
	local targetPosY = mouse.Target.Position.Y --y position of part clicked
	isRemote:FireServer(targetPosY) --use this value in a server script to position the ice spikes
end)

You can also replace Position with CFrame or use the CFrame of the character’s HumanoidRootPart in order to correctly orientate/direct the ice spikes.

uh no, it’s not gonna activate when the mouse is clicking on a part… when you press z it summons the spikes in front of you… and I’ve already done that now I just need help on positioning. I’ve also found the problem,

This is my script:

return function(plr)
	local tweenservice = game:GetService("TweenService")
	local tweeninfo = TweenInfo.new(0.35, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
	local mouse = plr:GetMouse()
	local mouseCF = mouse.Hit
	local mousePos = Vector3.new(mouseCF.Position.X,plr.Character.HumanoidRootPart.Position.Y,mouseCF.Position.Z)
	local start = plr.Character.HumanoidRootPart.CFrame
	-- local goal = start.LookVector * 70
	local spikesNum = math.random(4, 4)
	local shardIncrements = 70 / spikesNum
	for i = 1, spikesNum do
		local newSpike = script.IceSpike:Clone()
		newSpike.Anchored = true
		newSpike.CanCollide = false
		local x, y, z = 20 * i, 4 * i * 5, 10 * i
		local yy = 8* i
		newSpike.Size = Vector3.new(0, 0, 0)
		local pos = plr.Character.HumanoidRootPart.Position + start.LookVector * (shardIncrements * i)
		local ypos = plr.Character.HumanoidRootPart.Position.Y
		local ori = plr.Character.HumanoidRootPart.Orientation
		newSpike.Position = Vector3.new(pos.X, pos.Y , pos.Z)
		newSpike.Orientation = plr.Character.HumanoidRootPart.Orientation + Vector3.new(0, 270, 0)
		local newSize = Vector3.new(x, yy, z)
		local newPos = newSpike.Position -- + Vector3.new(0, 8/2.5, 0)
		local tween = tweenservice:Create(newSpike, tweeninfo, {Size = newSize, Position = newPos})
		newSpike.Parent = workspace
		tween:Play()
		local charactersHit = {}
		
		 local parts = workspace:GetPartsInPart(newSpike)
		
		--[[ if parts:IsA("BasePart") then
			if parts.Parent:IsA("Model") then
				if parts.Parent["Humanoid"] then
					local hum = parts.Parent:WaitForChild("Humanoid")
					hum:TakeDamage(30)
				end
			end
		end  --]]
		
		coroutine.resume(coroutine.create(function()
			wait(3)
			local reverseTween = tweenservice:Create(newSpike, tweeninfo, {Size = Vector3.new(0, 0, 0), Position = Vector3.new(pos.X, 0, pos.Z)})
			reverseTween:Play()
			reverseTween.Completed:Wait()
			newSpike:Destroy()
		end))
		wait(math.random(1, 100)/1000)
	end
	plr.Busy.Value = false
	print("z move done!")
end

The problem is the local yy = 8* i part. This is what happens, they go up to down instead of being aligned

but if I set it to just 8, it perfectly aligns but doesn’t have the part where it sets the size according to the position it’s in, for example the first spike is supposed to be small, then the last one as largest.

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local uis = game:GetService("UserInputService")
local rs = game:GetService("ReplicatedStorage")
local isRemote = rs:WaitForChild("IceSpikesRemote")

uis.InputBegan:Connect(function(input, processed)
	if processed then
		return
	end
	
	if input.KeyCode == Enum.KeyCode.Z then
		local target = mouse.Target
		local targetPosY = mouse.Target.Position.Y --y position of part clicked
		isRemote:FireServer(targetPosY) --use this value in a server script to position the ice spikes
	end
end)

I’m sorry but I dont think you get my problem, I’ve edited my previous reply.
Also I USE modulescripts, not remote events, if you can tell from the script in my previous reply, there’s a return function, sorry for the confusion.