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.
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.
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)
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.
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