I was creating earth magic and I made spikes that come out of the ground with the same color and material
input - local script :
local re = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
inputservice.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
local root = character:WaitForChild("HumanoidRootPart")
local pos = Vector3.new(root.Position.X, math.floor(root.Position.Y)-3,root.Position.Z) --make a grid at the Y position
local orien = Vector3.new(0,root.Orientation.Y,0) --makes the spike angle not change if the character is down or standing
re:FireServer(pos,orien)
end
end)
spike creation - script :
local re = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
local spike = game:GetService("ServerStorage"):WaitForChild("Spike")
re.OnServerEvent:Connect(function(plr,pos,orien)
for i = 1,10 do --10 means how many spikes will be created
wait(.1)
local spike = spike:Clone()
spike.Orientation = orien
spike.Position = pos
spike.CFrame += spike.CFrame.LookVector *(4*i+i) --makes the thorn advance to its final position
spike.Size = Vector3.new(2+i,4*i,2+i)
spike.Position += Vector3.new(0,spike.Size.Y/2 ,0) --makes the spike stay above ground
local ray = Ray.new(Vector3.new(spike.Position.X,spike.Position.Y,spike.Position.Z) , Vector3.new(0, -(2*i+.1), 0) ) --check the ray API
local hit = workspace:FindPartOnRayWithIgnoreList(ray, {spike})
if not hit then return end --if the spike is on the ground (if the ray hit something)
spike.Color = hit.Color
spike.Material = hit.Material
spike.Orientation += Vector3.new(-25,0 ,math.random(-15,15)) --makes the spike vary its angle a little
spike.Position += Vector3.new(0,-((i+1)/2),0) --makes the spike go down a little and enter the ground
spike.Anchored = true
spike.Parent = workspace
game.Debris:AddItem(spike,5) --destroy spike after 5 seconds
end
end)