Server script in ServerScriptService won't run Onserverevent fired from local script

ServerScript:

local getToolsEvent = game:GetService("ReplicatedStorage").GetTools
getToolsEvent.OnServerEvent:Connect(function(myFolder)
	print(myFolder.Name)
end)

Local script:

local getToolsEvent = game:GetService("ReplicatedStorage").GetTools
game.Players.PlayerRemoving:Connect(function()
	local myTools = {myFolder:FindFirstChildWhichIsA("StringValue")}
	getToolsEvent:FireServer(myTools)
end)

When a function is activated by OnServerEvent, it will always send through the player who activated the RemoteEvent before any additional data. This means that an additional parameter needs to be added before “myFolder” (or else “myFolder” will just refer to the player object).

Revised Code:

getToolsEvent.OnServerEvent:Connect(function(player, myFolder)
	print(myFolder.Name)
end)

Useful additional resource:

Remote Events and Callbacks (Quick Reference section) - Roblox Creator Documentation site

I didn’t know that, unfortunately nothing is still being printed in the output, no errors too.

I think in this use case handling on the server is best, since the LocalScript of the leaving player gets deleted (I may be wrong though):

local function getTools(myFolder)
print(myFolder.Name)
end

game.Players.PlayerRemoving:Connect(function(player)
local myFolder -- path to myfolder. if you need the localPlayer then "player" is your leaving player
local myTools = {myFolder:FindFirstChildWhichIsA("StringValue")}
getTools(myTools)
end)

where is that even leading to or refencing … Parts of this script are missing.

It contains the value of the tool they have

game.Players.PlayerRemoving:Connect(function()
	print(getToolsEvent)
	local myTools = {myFolder:FindFirstChildWhichIsA("StringValue")}
	print(myTools)
	getToolsEvent:FireServer(myTools)
end)

All lines of code worked perfectly even the second print function. I think the issue is located in the serverscript in server script service:

local getToolsEvent = game:GetService("ReplicatedStorage").GetTools
getToolsEvent.OnServerEvent:Connect(function(player, myFolder)
	print(myFolder.Name)
end)

image

From where? myFolder is not even defined.

local myFolder = game:GetService("ReplicatedStorage").Folder:Clone()
myFolder.Parent = game.Players.LocalPlayer
myFolder.Name = game.Players.LocalPlayer.Name.."'s tools"
local getToolsEvent = game:GetService("ReplicatedStorage").GetTools
game.Players.PlayerRemoving:Connect(function()
	print(getToolsEvent)
	local myTools = {myFolder:FindFirstChildWhichIsA("StringValue")}
	print(myTools)
	getToolsEvent:FireServer(myTools)
end)

I am so silly, I put “myFolder” instead of “myTools”… Thanks to all the replies

lol was just thinking why isn’t that named mytools :rofl: