Earth magic spikes

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)
20 Likes

Shouldnt this be in #resources:community-resources ?
Also good job!

3 Likes

This looks like something that you play with in the old script builder games, great job

2 Likes

These look very similar to Elemental Battlegrounds’ “Aciculate Spikes” spell.
Did you base it off that?

2 Likes

Why is there an elseif but not an if in the local script?

1 Like

This looks very good, but I recommend putting raycast on client if you can.

1 Like

This was because within the event there were several input comparisons to other magic attacks , when I published this post I only put the spike magic input code and forgot to change elseif to if

I will change it now

couldn’t you also use :lerp()?

Wow, can I use this in my game? I would give credit.

1 Like

This is really cool! Also this is really useful for people trying to understand how to use CFrame in a script.

A nice resource, however I would like to give some feedback.

  • Use task.wait instead of wait since wait is deprecated
  • Use the new workspace:Raycast() instead of Ray.new