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

How Could i make this wand Shoot Spells in the Mouse's Direction?

Asked by 4 years ago

Alright so I'm trying to make a HP Wand, and i'm facing a Setback, RN the Only way to make my wands work is Lookvector, I don't know How to Make it Face the Way my Mouse is Facing, Everything else Works Fine. Heres my Code

****Local****

local ReplicatedStorage = game.ReplicatedStorage
local event = ReplicatedStorage.AvadaKedavra
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Green = script.Parent.Attachment.Green
local Purple = script.Parent.Attachment.Purple
local Blue = script.Parent.Attachment.Blue
local Orange = script.Parent.Attachment.Orange
local Red = script.Parent.Attachment.Red
local Pink = script.Parent.Attachment.Pink

player.Chatted:Connect(function(msg)
    local msg = msg:lower()
    if msg:match("avada kedavra") then
        local spell = true
        Green.Enabled = true
        -- Clicked
        mouse.Button1Down:Connect(function()
            if spell then
        event:FireServer(mouse.Hit.p)
            Green.Enabled = false
                spell = false
            end
        end)
    end
end)

****Server****

local Spell = game.ServerStorage:WaitForChild("Spell")

game.ReplicatedStorage.AvadaKedavra.OnServerEvent:Connect(function(player)
    local character = player.Character
    local newSpell = Spell:Clone()
    newSpell.CFrame = character.HumanoidRootPart.CFrame


    local bodyVelocity = Instance.new("BodyVelocity")
    bodyVelocity.MaxForce = Vector3.new(500,500,500)
    bodyVelocity.Velocity = (character.HumanoidRootPart.CFrame.lookVector*250)
    bodyVelocity.Parent = newSpell

    newSpell.Parent = workspace

    local touchConn

    touchConn = newSpell.Touched:Connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") then
            if hit.Parent.Name ~= player.Name then
                hit.Parent:BreakJoints()
                if touchConn ~= nil then touchConn:Disconnect() end
                local Debris = game.ServerStorage.Debris:Clone()
                Debris.Parent = newSpell
                bodyVelocity:Destroy()
                wait(2)
                newSpell:Destroy()
            end
        end
    end)


    wait(30)

    if touchConn == nil then touchConn:Disconnect() end
    local Debris = game.ServerStorage.Debris:Clone()
    Debris.Parent = newSpell
    bodyVelocity:Destroy()
    wait(2)
    newSpell:Destroy()
end)

Could anyone Help me Figure this Out?

0
can't you just do mouse.hit.p? ImUID3558 20 — 4y
0
could i get some code? godzilla_fan15 2 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Ok i Found it Out Myself after hours

Ad

Answer this question