How do I make mouse position for my fireball?

I’ve made a fireball with some help. But, instead of it going to the look vector how do I make go where the mouse position is? I know I can use Mouse.Hit.p. But, I don’t know how those things work so any examples would be great!

Some of the script:

local Clone = Fireball:Clone()
Clone.Parent = workspace
Clone.Position = Character.HumanoidRootPart.Position + Character.HumanoidRootPart.CFrame.LookVector * Offset
game.Debris:AddItem(Clone, 5)

local BodyVel = Instance.new("BodyVelocity")
BodyVel.Parent = Clone
BodyVel.MaxForce = Vector3.new(math.huge, math.huge, math.huge)

BodyVel.Velocity = Character.HumanoidRootPart.CFrame.LookVector * Speed

Thank you, and have a great day.

1 Like

For this, you need to use CFrame, BodyVelocity, and Mouse.Hit.p.

local Clone = Fireball:Clone()
local mouse = plr:GetMouse()
Clone.Parent = workspace
Clone.Position = Character.HumanoidRootPart.Position + Character.HumanoidRootPart.CFrame.LookVector * Offset
game.Debris:AddItem(Clone, 5)

local BodyVel = Instance.new("BodyVelocity")
BodyVel.Parent = Clone
BodyVel.MaxForce = Vector3.new(1e6,1e6,1e6)
BodyVel.Velocity = CFrame.new(Clone.Position, mouse.Hit.p).LookVector * 60

Clone:SetNetworkOwner(plr)

If this works, please set this post as the Solution! Thanks!

2 Likes

When I press the key the fireball just starts floating up slowly.

Hmm, well, did you position the mouse properly and then press the key?

I would suggest binding the fireball to a MouseDown event, so that wherever you click, the fireball fires.

Yes even if I put my mouse behind myself it still spawns in front of me and start floating up.

How does the fireball get fired exactly? I mean, do you hold a tool, or is it just powered by UserInputService?

User Input Service. When a player presses the keycode it fires a event etc.

Ah. So this is from a Server Script. Well, it should work…
I mean, I use something like this for my knife throw…
Try this out:

local position = Character.HumanoidRootPart.Position + Character.HumanoidRootPart.CFrame.LookVector * Offset
Clone.CFrame = CFrame.new(position, mousePos)
local BodyVel = Instance.new("BodyVelocity")
BodyVel.Parent = Clone
BodyVel.MaxForce = Vector3.new(1e6,1e6,1e6)
BodyVel.Velocity = CFrame.new(Clone.Position, mouse.Hit.p).LookVector * 60
Clone.Parent = workspace

It’s under the local script which tests if the player pressed the key.

Try changing it to something like this!

local FORCE = 200

local position = Character.HumanoidRootPart.Position + Character.HumanoidRootPart.CFrame.LookVector * Offset
Clone.CFrame = CFrame.new(position, mousePos)
local BodyVel = Instance.new("BodyVelocity")
BodyVel.Parent = Clone
BodyVel.MaxForce = Vector3.new(1e6,1e6,1e6)
BodyVel.Velocity = CFrame.new(Clone.Position, mouse.Hit.p).LookVector * FORCE
Clone.Parent = workspace

So it just makes it go up faster. I don’t think the mouse position works because it just spawns right in front of me.

Im new to fourms but maybe its like this IDK how to make it scrollable text thing
local Fireball = game.ServerStorage:WaitForChild(“Fireball”)
local Clone = Fireball:Clone()

local Character = Player.Character
Clone.Parent = workspace
Clone.Position = Character.HumanoidRootPart.Position + Character.HumanoidRootPart.CFrame.LookVector * 1

game.Debris:AddItem(Clone, 5)

local BodyVel = Instance.new(“BodyVelocity”)
BodyVel.Parent = Clone
BodyVel.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
BodyVel.Velocity = CFrame.new(Clone.Position, mousehit).LookVector * 30

Clone:SetNetworkOwner(Player)

Shouldn’t this be mouse.hit? Not mousehit I currently can’t test it so oof.

Yeah sorry I think you have to use local script and use fireserver cause it works when I do it like that

local mouse = game.Players.LocalPlayer:GetMouse()

local mousehit = mouse.Hit.p
Fireball:FireServer(mousehit)

Should there be a variable recognizing mouse hit in the event script?

local rp = game:GetService("ReplicatedStorage")
local Fireball= rp:WaitForChild("Fireball")
Fireball.onServerEvent:Connect(function(Player,mousehit)

-- then just insert previous code and it will work I think

end)

Let me test this, sorry I might have a late response.

Its okay I’m new to dev forum and dont know much lol

After the input has began you should connect to the server using a remote event passing the mouse position as one of the arguments
On the server script clone the fireball into the workspace and add a BodyForce on to it so that it stays up or else because of gravity the fireball may go in that direction but it will fall
to define the bodyforce do this:
local BodyF= Instance.new(“BodyForce”)
BodyF.Force = Vector3.new(0,clonedpart:GetMass * workspace.Gravity,0)
BodyF.Parent = clonedpart
So here we make the part stay up in the air and now you want it to travel the direction of where your mouse is
to define this simply do this:
local direction = (mousepos - originpos).Unit*100 --Origin pos is where ur part will spawn
now the direction is defined and make sure these are on server script after the input has began.
Now to make the part travel in that direction make the velocity of the part equal to the direction
clonedpart.Velocity = direction
Now the part will travel in that direction.

Oof it doesn’t work also to make the scroll thing press the </>