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

(UPDATED,NEW PROBLEM)bad argument #2(Vector3 expected,got Object)?

Asked by 3 years ago
Edited 3 years ago

Hello,I was trying to make a simple gun with remote events,but this error is happening to me. "bad argument #2(Vector3 expected,got Object)" on the server script.Anyways,the local script of the gun is this one:

local BulletEvent = game:GetService("ReplicatedStorage"):WaitForChild("BulletShoot")
local Tool = script.Parent
local Player = game.Players.LocalPlayer

Tool.Equipped:Connect(function(mouse)

    mouse.Button1Down:Connect(function()

    BulletEvent:FireServer(Player,Tool.Handle.Shoot.Position, mouse.Hit.Position)
    end)
end)

And for the remote event:

local BulletEvent = game:GetService("ReplicatedStorage"):WaitForChild("BulletShoot")
local RS = game:GetService("ReplicatedStorage")


BulletEvent.OnServerEvent:Connect(function(Player,FromP,ToP)
    local castRay = Ray.new(FromP, (ToP - FromP).unit * 100)
        local hit,Position = workspace:FindPartOnRay(castRay, Player.Character)

        if hit then
          local Human = hit.Parent:FindFirstChild("Humanoid")
           if Human then
              Human:TakeDamage(20)
           end

        end
        local Laser = Instance.new("Part",workspace)
        Laser.BrickColor = BrickColor.new("Really red")
        Laser.Material = "Neon"
        Laser.CanCollide = false
        local Dist = (ToP - FromP).magnitude
        Laser.CFrame = CFrame.new(FromP, Position)
        Laser.Size = CFrame.new(0.1,0.1,Dist) * CFrame.new(0,0,-Dist/2)
        game.Debris:AddItem(Laser,0.01)


end)

Tell me if you need other scripts.I would really appreciate if you can solve this problem.(2x)

Thanks.

0
Can you give us the exact error? Nckripted 580 — 3y
0
The line 6 is not needed,and the line will be deleted. trustydoggy 24 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

You're searching for the gun in the player's backpack. When someone equips a tool, it'll appear in the Workspace in their character model.

Replace line 6 with:

local Gun = Player.Character.Gun -- you don't need to :FindFirstChild -- the gun is already equipped
0
Thanks,but this was an old answer. trustydoggy 24 — 3y
Ad

Answer this question