Attempt to index nil with 'FireServer'

So basically my friend was coding a tool for a zombie spawner, it spawns the zombie from replicated storage to the mouse position, but it was not working

heres the local script (it activates a remote function which spawns the zombie)

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

local Event = script:FindFirstChildWhichIsA("RemoteEvent")

Mouse.Button1Down:Connect(function()
    local Character = Player.Character
    local ThisTool = Character:FindFirstChildWhichIsA("Tool")
    if ThisTool ~= nil then
	    Event:FireServer(Mouse.hit)
    end
end)

serverside script:

local RemoteEvent = script.Parent:FindFirstChildWhichIsA("RemoteEvent")

local RepSt = game.ReplicatedStorage
local Zombie = RepSt:FindFirstChild("Zombie")

RemoteEvent.OnServerEvent:Connect(function(mousehit)
    print("work")
    local ZombieMinion = Zombie:Clone()
    local Root = ZombieMinion.PrimaryPart
    Root.Position = Vector3.new(mousehit)
end)
1 Like

You haven’t passed the Player parameter. Change it to .OnServerEvent:Connect(function(Player,mousehit)

1 Like

it still has the “Attempt to index nil with ‘fireserver’,” the error is coming from the local script, not the server script, so it will not fire the server script because of the error

ServerScript was another problem so my post above is part of the solution.

LocalScript:
Just do :FindFirstChild("RemoteEvent") there is no reason why you need to do script:FindFirstChildWhichIsA.

Can you show the explorer? It would be helpful.

Here:

Screen Shot 2021-03-21 at 7.18.47 PM 1

Event is nil because FindFirstChildWhichIsA is returning nil - the event is most likely replicated after the script checks for it. Try replacing FindFirstChildWhichIsA with WaitForChild.

4 Likes

It works, thank you so much for the help!

1 Like

Keep in mind your server script won’t work since your mousehit is being defined as the player.

1 Like