Attempt to index nil with "FireServer()"

Hello! So I am currently trying to make a meme gun and I’m attempting to do so using RemoteEvents, and my experience with them is not that great.

I keep getting this error: attempt to index nil with 'FireServer' whenever my tool is activated.

Client:

local tool = script.Parent
local RemoteEvent = tool:FindFirstChildOfClass("RemoteEvent")

tool.Activated:Connect(function()
	RemoteEvent:FireServer()
end)

Server:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Memes = ReplicatedStorage.Memes

local tool = script.Parent
local RemoteEvent = tool:FindFirstChild("RemoteEvent")
local Handle = tool:FindFirstChild("Handle")

RemoteEvent.OnServerEvent:Connect(function(Player)
	local RandomMeme = Memes[math.random(1, #Memes)]:Clone()
	
	local function FireMeme()
		RandomMeme.Anchored = true
		RandomMeme.Position = tool.Handle.Position + Vector3.new(0, 0, -5)
		RandomMeme.Parent = workspace

		local BodyVelocity = Instance.new("BodyVelocity")
		BodyVelocity.Velocity = tool.Handle.CFrame.LookVector * 50
		BodyVelocity.Parent = RandomMeme

		task.wait(5)
		RandomMeme:Destroy()
	end
end)

If you think you know what went wrong, please let me know! Thank you and have a wonderful day! :slight_smile:

It looks like the client isn’t finding the remote event. Try changing the local RemoteEvent value to tool.RemoteEvent or tool:WaitForChild("RemoteEvent") and also make sure the remote event’s name is RemoteEvent

2 Likes

It is not finding the RemoteEvent in this line:

local RemoteEvent = tool:FindFirstChildOfClass("RemoteEvent")

Try a different way using a WaitForChild.

2 Likes

Using :WaitForChild() worked! For some reason, it didn’t before. But now, the memes don’t fire from the tool’s handle.

Are you calling the function anywhere? In the remote event you’re just defining it

1 Like

It worked! My problems today have just been easy solutions! Where has my mind been? Thank you guys for helping me and have a wonderful day! :slight_smile:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.