FireServer will not pass variable

Hello,

Trying to use this code:

client:

tool = script.Parent
fireServer(tool)

server:

OnServerEvent:Connect(function(plr, tool)

Seems simple enough right? NOPE!

a print(tool) in the client script shows the tool

a print(tool) in the server script shows NIL

The RemoteEvents are the same name, and the player instance gets passed, so I know that part works.

what’s going on?

2 Likes

The first parameter of a remote event is the player who fired it, do (player,tool) inside the function part

1 Like
local tool = script.Parent
local event = game.Service.Event -- game > Service | like game.ReplicatedStorage

event:FireServer(tool)
local event = game.Service.Event -- game > Service | like game.ReplicatedStorage

event.OnServerEvent:Connect(function(Player, tool)
    print(tool)
end)

Whether I call the Player variable “plr”, “player” or “Player” the outcome is the same :frowning:

2 Likes

I’m not fully sure if your able to print an instance so try

print(tool.Name)

Edit: also check your output for errors and if you see any send them

It doesn’t matter what the name of the player is, it can be set to player, donkey, plane, helicopter, it doesn’t matter. @jake_4543 , just as long as the player is set then it’ll work.

@QuantumDonkeyFart how many tools do you have in the client? If it’s only one, or multiple, whatever you’re trying to do on the server could be a lot easier. What I usually do for my clicker tools, I put them all in a module, define them by name, and then on the server I FindFirstChildOfClass on either the player’s backpack, or the player’s character ( since the tool gets moved to the character once equipped ). If the tool doesn’t exist, they don’t have one ( the server shouldn’t have been fired anyways if the tool wasn’t equipped, so just look in their character and make sure they’re not exploiting ).

Edit:

Also wanted to ask, are you creating the tools on the client or the server? If they’re being created in a LocalScript ( or the client ) then that explains a lot. Creating stuff on the client wont replicate to the server ; meaning other players and the server wont be able to see it. If you’re creating tools on the client, convert to creating them on the server. This could be your issue.

So basically it’s a pickpocket tool.

You equip the tool, bump into another player, and steal some of their stuff.

I’m stuck on this bit though.

I know the event works cos it’s a copy&paste&rename job from the 6 other tools I’ve already created (which all work)

1 Like

Hi,

Like I said, the print statement works in the client script, it just isn’t passing the variable to the server.

1 Like

Hi, the tools are in ReplicatedStorage and get cloned to the player when equipped. This method has worked for my other tools (6 of them) and works for this, but the local script in the tool is only passing Player, and not the tool variable.

1 Like

As Kensizo said is the tool created or added to your players backpack on the client? If so that’s your issue

Hi, created by clone from replicated storage

1 Like

Did you clone it on the client if so that’s your issue

Player clicks GUI button, remote event called to server script that creates the tool and places it in player, like i said, there are 6 other tools working without issue.

1 Like

I’m not sure then. Weird issue I’ll try searching for anyone who’s had an issue like this or a fix for it.

Been googling this for 3 hours. There’s nothing.

1 Like

The tool is locally cloned so it will not replicate to the Server, therefore it will be nil.

To make both of them not nil, both of them will have to see it(meaning that both of them can reference it). In this case, the client has something the server cannot see. This is just like if you send an object from ServerStorage to the client, even though the server can see it, the client cannot, therefore the object becomes nil.

So, put your tool into replicated service and keep the script where it is, and do something like this:

local tool = game:GetService("ReplicatedStorage"):WaitForChild(ToolnameHere)
fireServer(tool)

Don’t clone the tool from the client, clone the tool from the server.

5 Likes

I believe you can’t send models via fire server, you might need to try a different method to locate the tool.

This post is 2 years old, for future reference don’t necro on posts