How do I make a simple ranged magic spell?

I recommend not parenting the bullet to the character, Because if another bullet hits that bullet it could damage the players shooting the bullet. Which is not what you want I assume

1 Like

Also if this is in a local script, none of the other players can see it, only the player that shot it. So you want to fire on a remote event to the server to make a new bullet

It’s a regular script. Oh, and I forgot to copy the staff variable. It’s at the top of the code.

OK i see, can I see what the top of the code looks like?

It’s only the staff variable. The script is underneath the tool object called ‘Staff’.

local Staff = script.Parent
local bullet = Instance.new("Part")
local Root= game.Workspace:WaitForChild("zenxatic"):WaitForChild("HumanoidRootPart")

local function onActivation()
	bullet.Parent = game.Workspace
	bullet.CanCollide = false
	bullet.Anchored = true
	bullet.Position = Root.Position
	bullet.Transparency = 0
	print("Test")
end

Staff.Activated:Connect(onActivation)

I Tried this out and it works for me.
This is a normal script in the tool
Also in the tool, Make sure it has a part named “Handle” In it
Also when doing anything with the player, you typically want to only use the player’s HumanoidRootPart and not the torso.

Alright, I’ll see and I’ll mark this as the solution if it works.

Sadly, it didn’t work. This is what I get in the output.

03:55:06.896 InsertService cannot be used to load assets from the client - Client
03:55:06.896 Stack Begin - Studio
03:55:06.897 Script ‘cloud_1292342678.PathfindingMaker.ButtonScript’, Line 13 - Studio
03:55:06.897 Stack End - Studio
03:55:06.899 cloud_142613350.EmptyScriptAdder:7: Incomplete statement: expected assignment or a function call - Studio
03:55:09.250 0.5, 0.5 - Server
03:55:09.538 0.5, 0.5 - Client

Im, making a script rn, I will give it to you to test. Soon

does your tool look this?
image

image

local Staff = script.Parent


local function onActivation()
	local bullet = Instance.new("Part")
	bullet.Parent = game.Workspace
	bullet.CanCollide = false
	bullet.Anchored = true
	bullet.Position = Staff.Parent.HumanoidRootPart.Position
	bullet.Transparency = 0
	print("Test")
end

Staff.Activated:Connect(onActivation)

How about this

Still isn’t working…
Dang what did I do wrong?

I made a brand-new world and pasted the tool on ground, picked it up, and it worked. Your output you showed had a lot of random stuff from other scripts. Can you create a new world real quick and test it

This kinda works, Somethings wrong with the direction of the spell

local Tool = script.Parent

local Char
local HumRoot



local TweenServ = game:GetService("TweenService")

----Functions

local SpellCastDist = 50
local Speed = 0.3

function LaunchSpell(Port,Dirct,Dmg)
	if Char ~= nil then
		print("SpellShot")
		local Spell = Instance.new("Part",workspace)
		Spell.Size = Vector3.new(1,1,1)
		Spell.Material = Enum.Material.Neon
		Spell.Anchored = true
		Spell.CanCollide = false
		Spell.CFrame = Port.CFrame
		---CreateSpell^^
		local TouchEnabled = nil
		print((Port.Position - Dirct).Magnitude)
		
		local TweenSpell = TweenServ:Create(Spell, TweenInfo.new((Port.Position - Dirct).Magnitude*Speed), {Position = Dirct})
		TweenSpell:Play()
		
		while TouchEnabled == nil do
			wait()
			Spell.Touched:Connect(function(hit)
				if hit and hit.Parent ~= Char and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
					TouchEnabled = false
					hit.Parent:FindFirstChild("Humanoid"):TakeDamage(Dmg)
				end
			end)
		end	
	end
end

Tool.Activated:Connect(function()
	if Char and HumRoot then
		LaunchSpell(HumRoot, HumRoot.CFrame.LookVector*SpellCastDist, 30)
	end
end)

Tool.Equipped:Connect(function()
	Char = Tool.Parent
	HumRoot = Char:WaitForChild("HumanoidRootPart")
end)

Tool.Unequipped:Connect(function()
	Char = nil
	HumRoot = nil
end)

Put this in the script…

I Fixed it

local Tool = script.Parent

local Char
local HumRoot



local TweenServ = game:GetService("TweenService")

----Functions

local SpellCastDist = 50
local Speed = 0.1

function LaunchSpell(Port,Dirct,Dmg)
	if Char ~= nil then
		local Spell = Instance.new("Part",workspace)
		Spell.Size = Vector3.new(1,1,1)
		Spell.Material = Enum.Material.Neon
		Spell.Anchored = true
		Spell.CanCollide = false
		Spell.CFrame = Port.CFrame
		---CreateSpell^^
		local TouchEnabled = nil
		local SpellSpeed = (Port.Position - Dirct).Magnitude*Speed
		
		local TweenSpell = TweenServ:Create(Spell, TweenInfo.new(SpellSpeed), {Position = Dirct})
		TweenSpell:Play()
		
		while TouchEnabled == nil do
			wait()
			Spell.Touched:Connect(function(hit)
				if hit and hit.Parent ~= Char and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
					TouchEnabled = false
					hit.Parent:FindFirstChild("Humanoid"):TakeDamage(Dmg)
				end
			end)
		end	
	end
end

Tool.Activated:Connect(function()
	if Char and HumRoot then
		LaunchSpell(HumRoot, (HumRoot.Position + HumRoot.CFrame.LookVector*SpellCastDist), 30)
	end
end)

Tool.Equipped:Connect(function()
	Char = Tool.Parent
	HumRoot = Tool.Parent:WaitForChild("HumanoidRootPart")
	print(Char)
end)

Tool.Unequipped:Connect(function()
	Char = nil
	HumRoot = nil
end)

image
I think I fixed it

1 Like

Hehe, that’s just what I did, Nice.

1 Like

This script i made doesn’t delete the spell block, but i think you can do that

local Tool = script.Parent

local Char
local HumRoot



local TweenServ = game:GetService("TweenService")

----Functions

local SpellCastDist = 50
local Speed = 0.02

function LaunchSpell(Port,Dirct,Dmg)
	if Char ~= nil then
		local Spell = Instance.new("Part",workspace)
		Spell.Size = Vector3.new(1,1,1)
		Spell.Material = Enum.Material.Neon
		Spell.Anchored = true
		Spell.CanCollide = false
		Spell.CFrame = Port.CFrame
		---CreateSpell^^
		local TouchEnabled = nil
		local SpellSpeed = (Port.Position - Dirct).Magnitude*Speed
		
		local TweenSpell = TweenServ:Create(Spell, TweenInfo.new(SpellSpeed,Enum.EasingStyle.Linear), {Position = Dirct})
		TweenSpell:Play()
		
		TweenSpell.Completed:Connect(function()
			TouchEnabled = false
			Spell:Destroy()
			print("SpellOver")
		end)
		
		while TouchEnabled == nil do
			wait()
			Spell.Touched:Connect(function(hit)
				if hit and hit.Parent ~= Char and hit.Parent and hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("Humanoid").Health > 0 then
					TouchEnabled = false
					print("Touched"..hit.Parent.Name)
					hit.Parent:FindFirstChild("Humanoid"):TakeDamage(Dmg)
					Spell:Destroy()
				end
			end)
		end	
		
	end
end

Tool.Activated:Connect(function()
	if Char and HumRoot then
		LaunchSpell(HumRoot, (HumRoot.Position + HumRoot.CFrame.LookVector*SpellCastDist), 30)
	end
end)

Tool.Equipped:Connect(function()
	Char = Tool.Parent
	HumRoot = Tool.Parent:WaitForChild("HumanoidRootPart")
	print(Char)
end)

Tool.Unequipped:Connect(function()
	Char = nil
	HumRoot = nil
end)