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

How do I make the projectile fire from the tool?

Asked by 6 years ago

I want to create a basic tool which shoots things out depending on the name of it. However, at the moment, it teleports the part to the place a click and then moves. Rather than me click in the place and the projectile flying from my tool to that location..

Here's my code for my local script:

local Tool = script.Parent
local toolTip = script.Parent.Handle

Tool.Equipped:connect(function(Mouse)
    Mouse.Button1Down:connect(function()

        game.ReplicatedStorage.Powers:FireServer(Mouse.Hit, Tool.Handle)

    end)
end)

My code from my server script:

game.ReplicatedStorage.Powers.OnServerEvent:Connect(function(player, MouseHit, Handle)
  print(player, MouseHit, Handle)
  if player.Spell.Value == "Water" then
    local S1 = Instance.new("Part",workspace)
    local S1b = Instance.new("BodyVelocity")
    S1.CFrame = MouseHit
    S1.Anchored = false
    S1.CanCollide = false
    S1.formFactor = "Symmetric"
    S1.Shape = "Ball"
    S1.Size = Vector3.new(1,1,1)
    S1.TopSurface = "Smooth"
    S1.BottomSurface = "Smooth"
    S1.Transparency = 0.5
    S1.Elasticity = 1
    S1.Friction = 0
    S1.BrickColor = BrickColor.new("Bright blue")
    S1b.Velocity = (MouseHit.p - Handle.CFrame.p).Unit * 200
    S1b.Velocity = (MouseHit.p - Handle.CFrame.p).Unit * 2
    S1b.Parent = S1

        game:GetService("Debris"):AddItem(S1, 2)

    end
end)


Thank you.

Answer this question