How do I make a simple ranged magic spell?

I have the model of the staff down, and I can’t seem to be able to do something which looks relatively simple. Basically, upon activating (the staff is a tool) the staff, it creates an instance inside the player’s torso which flies in the direction the player is facing.

So if the player was facing west, the “magic bullet” (let’s just call it that for now) would fly to the west, vice versa. When I try to activate the staff, nothing happens, no new part is summoned. I’ve tried to fix this for over 2 hours.

And yes, I was trying to use CFrames and other shenanigans to fix it (which I don’t normally use since I just came back from a 1 month break, I’m also really new).

2 Likes

Seeing the code would help us fix the issue. Do you think you forgot to parent the spell to workspace and that’s why you don’t see the magic bullet? Or maybe the tool itself does not activate properly when clicked?

I’ve already abandoned the actual place, I’m going to try again from scratch.

local bullet = Instance.new("Part")
local torso = game.Workspace.zenxatic.Torso

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

staff.Activated:Connect(onActivation)

Okay, here’s the code I tried to make. Still no success.

local Projectile = ""
Projectile.CFrame = Player.HumanoidRootPart.CFrame
local ProjectileDistance = 10
local FinalPosition = Player.HumanoidRootPart.CFrame + Player.HumanoidRootPart.CFrame.LookVector * ProjectileDistance

local Speed = 1

local tweenInfo = TweenInfo.new(
	Speed,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)
local tween1 = TweenService:Create(Cast.Root, tweenInfo, {CFrame = FinalPos})
tween1:Play()

If this is any help, This is generally what I use for my ranged projectiles. If you need more help I would not mind moving this to DM’s

Is this in a local script?
Also where do you define the staff variable

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