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

bad argument #2 (Vector3 expected,got Object) on the server script?

Asked by 3 years ago

Hello,back again with the gun thing;I made a last question about this before on other problem,but I changed the gun info.The error I get is of the title.The local script of the gun is:

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 the server script for the remote event(Error on line 6)

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)

Thanks. (EXTRA: If I update a question,I need to wait more for an new answer?)

1 answer

Log in to vote
0
Answered by 3 years ago

The player who fired the event is already a parameter of OnServerEvent so..

Make line 11 in the local script to this:

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

I just removed Player

Ad

Answer this question