Script things "nil with fire server" while trying to use remote event

  1. What do you want to achieve? Keep it simple and clear!
    I want to make my local script fire an event and my server script to pick it up.

  2. What is the issue? Include screenshots / videos if possible!

There is an error where it says "attempt to index nil with “FireServer”. And the Server script is not picking up the information I send it.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I looked at the developer hub and at some API and I tried some possible solutions but it didn’t work.

local Player = game.Players.LocalPlayer

local Mouse = Player:GetMouse()

local Tool = script.Parent

local Event = Tool:FindFirstChild("Shoot")

script.Parent.Equipped:Connect(function()
	local function OnClicked()
		Event:FireServer(Player,Mouse)
	end
	Mouse.Button1Down:Connect(OnClicked)
end)


local Tool = script.Parent

local Event = Tool:WaitForChild("Shoot")


 function OnFired(Player,Mouse)
	print(Mouse.Hit.Position)
end
Event.OnServerEvent:Connect(OnFired)

Sorry for my bad grammar, I am still in school.

can you send a screenshot of the tool inside explorer

sure, I’ll try to do it, one sec

it says “Sorry, there was an error uploading that file. Please try again.”

oh ok, it errors because it doesnt find Shoot inside the tool, make sure Shoot is parented to the tool instead of the handle or something else

1 Like

it is parented to the tool Picture-One — ImgBB

Well I suggest changing the FindFirstChild(“Shoot”) to WaitForChild(“Shoot”) as the event might not have loaded yet. Attempting to fire it in its unloaded state might cause it not to load properly after aswell.

That did make it work, but it is now saying “hit is not a valid member of the player”. Am I not sending the information right?

I see whats going on, remove the player argument on the local script as one is sent by defult.

When you fire the server you don’t include the Player. Another problem you will have is the server can’t access the mouse so you need to send the hit.position not just the mouse.

LocalScript:
Event:FireServer(Mouse.Hit.Position)

ServerScript:
function OnFired(Player,HitPosition)
	print(HitPosition)
end

Thx to Sunny_Bunny and Critical_Error for my solution. It works :slight_smile:

1 Like