Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make my Fireball go to where my Mouse points?

Asked by 5 years ago
Edited 5 years ago
local StarPack = game:GetService("StarterPack")
local RepStore = game:GetService("ReplicatedStorage")

StarPack.FireballF.OnServerEvent:Connect(function(plr)
    local char = plr.Character
    local x = RepStore.Fireball:Clone()
    x.Parent = workspace
    x.CFrame = char.UpperTorso.CFrame * CFrame.new(0,0,-4)
    x.CanCollide = false
    local v = Instance.new("BodyVelocity")
    v.Parent = x
    v.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
    v.Velocity = 
end)

local UIS = game:GetService("UserInputService")
local StarPack = game:GetService("StarterPack")
Ammo = 1

UIS.InputBegan:Connect(function(input)
if Ammo == 1 then
    if input.KeyCode == Enum.KeyCode.F then
        StarPack.FireballF:FireServer()
            Ammo = Ammo-1
            wait(2)
            Ammo = 1
        end
    end
end)

The first is the Script, the second is the Local Script v.Velocity should go to where the mouse points

1 answer

Log in to vote
1
Answered by
Arkrei 389 Moderation Voter
5 years ago
Edited 5 years ago

You can use the GetMouse() function to get where the mouse is exactly

you can get the players mouse by doing: local mouse = player:GetMouse() then you can use mouse.hit.p to get the position of your mouse, then you can sent that over to the server.

Within the server you can use the position that you sent to send the fireball towards that direction. To calculate the distance between where your character is and where the fireball needs to go do something like (currentPos- mousePos).magnitude

Hope this helps!

Ad

Answer this question