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

Making Blast Barrage In FE?(Continued)

Asked by 6 years ago

So I recently asked this question but I didn't put my code in with the question and thus, I still haven't gotten an answer. So what I am trying to do is make a move so that when a LocalScript notices that a key has been pressed, it calls a RemoteEvent to a Script inside a Tool. The Script then does the rest of the attack. The problem I am encountering is A) It isn't creating all 15 blasts and B) It can't track where my mouse is for each individual blast. I need it to be able to track for each individual blast because each blast should be able to be aimed in a separate direction. Please help! All the scripts are inside of a Tool, along with the RemoteEvent because they have to be for the purpose of my game. Here is the code:

LocalScript:

Player = script.Parent.Parent.Parent
mouse = Player:GetMouse()
Character = Player.Character

mouse.KeyDown:connect(function(key)
    if key == "q"  then
        wait()
    script.Parent.RemoteEvent:FireServer()
        end
end)

Script:

Player = script.Parent.Parent.Parent
mouse = Player:GetMouse()
Character = Player.Character

script.Parent.RemoteEvent.OnServerEvent:connect(function(player)
    wait()
    local originalspeed = Character.Humanoid.WalkSpeed
    Character.Humanoid.WalkSpeed = 0
    local circle = game.Lighting.GroundCircle:Clone()
    circle.Parent = Character.HumanoidRootPart
    circle.CFrame = Character.HumanoidRootPart.CFrame*CFrame.new(0, -2, 0)
    for i = 1, 10 do
        wait()
        circle.Size = circle.Size + Vector3.new(3, 0, 3)
    end
    for i = 1, 15 do
        wait()
        local sword = game.Lighting.Sword:Clone()
        sword.Parent = Character.HumanoidRootPart
        sword.CFrame = Character.HumanoidRootPart.CFrame*CFrame.new(0, -10, 0)
        for i = 1, 3 do
            wait()
            sword.Position = sword.Position + Vector3.new(0, 5, 0)
        end
        sword.Anchored = true
        sword.CFrame = Character.HumanoidRootPart.CFrame*CFrame.new(math.random(-10, 10), math.random(2, 8), -7)
        game.Debris:AddItem(sword, 10)
    end
    wait(0.1)
    local Search = Character.HumanoidRootPart:GetChildren()
         for i = 1, #Search do
            wait()
               if Search[i].Name == "Sword" then
        local BV = Instance.new("BodyVelocity")
        BV.Parent = Search[i]
        BV.maxForce = Vector3.new(math.huge, math.huge, math.huge)
        BV.Velocity = mouse.lookVector * 120-------------------------Need the mouse from here
        Search[i].CFrame = Character.HumanoidRootPart.CFrame*CFrame.new(math.random(-10, 10), math.random(2, 8), -7)
        Search[i].Anchored = false
        local SPOSs = Character.HumanoidRootPart.CFrame * Vector3.new(math.random(-10, 10), math.random(2, 8), -7)
        Search[i].CFrame = CFrame.new(SPOSs,mouse)
            end
                end---------------------------------------------------------------Up to here
        for i = 1, 10 do
            wait()
        circle.Size = circle.Size - Vector3.new(3, 0, 3)
        end
        circle:remove()
        Character.Humanoid.WalkSpeed = originalspeed
end)

Hope this can help with getting an answer. I've been stuck at a stand still with this code for a while and would really like to get it fixed.

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

So What I Assume You Want Is The Direction Vector Of The Mouse?

Note: The Code Must Be In A Local Script, So If You Need It With The Script, Then Feed It With The Remote Event

You Can Get It By Using The Code BelowVVV

local mouse = game.Players.LocalPlayer:GetMouse()--get the mouse
repeat wait() mouse = game.Players.LocalPlayer:GetMouse()--sometimes the mouse doesn't load the first time, so keep trying until it does
until mouse

local MouseLookVector = mouse.UnitRay.Direction

MouseLookVector*300 Will Be 300 Studs In The Direction Of The Mouse, MouseLookVector = 1 Stud In That Direction.

Edit: Thank you for the help. Yes, what I need is the direction vector. I'm still a little confused about how this code is going to help with getting the mouse vector to my script every time the loop runs.

The vector is the direction you want it to move. For example, this code would move the part in the direction of 'LookVector', which could be changed to MouseLookVector:

while wait(.1) do --change the wait to change how fast the fireball moves
    fireball.CFrame = fireball.CFrame+(LookVector*0.1)--this moves the fireball .1 stud in the direction of the mouse every .1 seconds
    --i use CFrame because settings it's position will not always work exactly.
end

Also, I am running the loop in a script so how would i feed it to the script via remote event while the loop is running?

if you want your code to keep going after the while wait() do, which is what i assume is what you want (correct me if i'm wrong), then you can use a function called a 'coroutine'.

coroutine.resume(coroutine.create(function()--this tells the script to start a 'coroutine', which is 'function()', running our bit of code in a coroutine, allowing the script to continue on.
    while wait() do
        --code here
    end
end))
print("The Code Continues On")--anything after the while loop will keep running

If there's any other questions you have, feel free to comment below. -REALTimothy0812

0
Thank you for the help. Yes, what I need is the direction vector. I'm still a little confused about how this code is going to help with getting the mouse vector to my script every time the loop runs. Sorry, I'm a pretty average scripter. Wolf5429 15 — 6y
0
Also, I am running the loop in a script so how would i feed it to the script via remote event while the loop is running? Wolf5429 15 — 6y
0
I edited my post to hopefully help some of your questions. If you need more help, we could team create. Let me know. User#20158 0 — 6y
Ad

Answer this question