Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make a bullet go in the directon of your mouse?

The main area of focus is round line 24. I've looked at many sources, but I still need help. So, I have A script that works great, but I need help getting the direction right. The fireball seems to go in one direction no matter which way it is facing. the script is below.

local Tool = script.Parent
local Handle = Tool:FindFirstChild("Handle")
local FireBallPart = game.ServerStorage:FindFirstChild("Union")
local enabled = true

local function Shoot(target)

if enabled == true then
	enabled = false
		local Ball = FireBallPart:Clone()
	local startPosition = Handle.Position
	local targetPosition = workspace.Part.position
	Ball.Parent = workspace
	Ball.CanCollide = true
	Ball.Anchored = false
	local BallCframe = CFrame.new(startPosition) + Vector3.new(.1,1,.1)
	
	
	Ball.CFrame = BallCframe

		Ball.CFrame = CFrame.new(Ball.Position,targetPosition)

		local BodyVelocity = Instance.new("BodyVelocity")
		BodyVelocity.velocity = BallCframe.lookVector * 10
		BodyVelocity.Parent = Ball
		print (BallCframe.lookVector)
	wait(1)
	enabled = true

	wait(50)
	Ball:Remove()
end

For testing, I just wanted it to go towards on part, but that didn't seem to work either.

1 answer

You'll want to get the mouse by using a RemoteEvent from the client (recommend putting the tools remotes inside of a folder thats in the tool)

LocalScript

local Tool = script.Parent
local Remotes = Tool.Remotes
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

Tool.Activated:Connect(function()
	Remotes.Shoot:FireServer(mouse.Hit)
end)

ServerScript

local Tool = script.Parent
local Handle = Tool:FindFirstChild("Handle")
local FireBallPart = game.ServerStorage:FindFirstChild("Union")
local enabled = true

local function Shoot(player,mouse)

if enabled == true then
    enabled = false
        local Ball = FireBallPart:Clone()
    local startPosition = Handle.Position
    local targetPosition = workspace.Part.position
    Ball.Parent = workspace
    Ball.CanCollide = true
    Ball.Anchored = false
    local BallCframe = CFrame.new(startPosition) + Vector3.new(.1,1,.1)


    Ball.CFrame = BallCframe

        Ball.CFrame = CFrame.new(Ball.Position,targetPosition)

        local BodyVelocity = Instance.new("BodyVelocity")
        BodyVelocity.velocity = mouse.LookVector * 90 --Speed
        BodyVelocity.Parent = Ball
        print (BallCframe.lookVector)
    wait(1)
    enabled = true

    wait(50)
    Ball:Remove()
end

Hope this helps!

4 comments

0

This helped a lot, and now I understand what I did wrong. But, what are remotes?

0

https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events They are instances used to communicate between the client and the server.

0

Thank you again, you seriously helped.

0

No problem, make sure to mark as the answer

This discussion is preserved as it was. New answers, comments, and votes are closed.