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

Handgun's Raycasting isn't working?

Asked by
Mr_Unlucky 1085 Moderation Voter
5 years ago

I'm making a handgun and for some reason the raycasting isn't working, can someone help? It displays an error saying on line 14 it's a bad argument and should use Vector3 instead.

local Tool = script.Parent
local ShootEvent = Tool:WaitForChild("Shoot")
local ReloadEvent = Tool:WaitForChild("Reload")

ShootEvent.OnServerEvent:Connect(function(player,tool,part,position,damage)
    local beam = Instance.new("Part", workspace)
    beam.BrickColor = BrickColor.new("Medium stone grey")
    beam.Material = "Metal"
    beam.Transparency = 0.25
    beam.Anchored = true
    beam.Locked = true
    beam.CanCollide = false

    local distance = (tool.Handle.CFrame.p - position).magnitude
    beam.Size = Vector3.new(0.3, 0.3, distance)
    beam.CFrame = CFrame.new(tool.Handle.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)

    game:GetService("Debris"):AddItem(beam, 0.1)
    if part then
        local humanoid = part.Parent:FindFirstChild("Humanoid")

        if not humanoid then
            humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
        end

        if humanoid then
            humanoid:TakeDamage(damage)
        end
    end
end)
0
is the "position' argument a CFrame value or a Vector3 value User#23365 30 — 5y

Answer this question