Passing instances through remote functions

Greetings all,

I’m attempting to pass an Instance through a remote function. For most people, using ReplicatedStorage would be fine to fetch these. However, I am storing weaponry in ServerScriptService and need the models themselves for display purposes in viewports. I could just make alternative versions of them and place them in ReplicatedStorage as well.

The reasoning for keeping them on the server though is to reduce exploitation. Yes I understand the minute I put it onto the client it becomes available to them though.

The question is, how could I pass an entire tool through to the client? I have this so far, but it errors out.

-- Client
local toolModel = game.ReplicatedStorage.Triggers.getWeaponTool("Melee", melee.serverName)
-- Server
function fetchWeaponModel(player, category, weapon)
	if checkHost(player) then
		local toolModel
		for _, tool in pairs(game.ServerStorage.Weapons[category][weapon].StarterPack:GetChildren()) do
			if tool:IsA("Tool") then
				local toolClone = tool:Clone()
				for _, children in pairs(toolClone:GetChildren()) do
					if children:IsA("LocalScript") or children:IsA("Script") then
						children:Destroy()
					end
				end
				toolModel = toolClone
			end
		end
		return toolModel
	end
end
game.ReplicatedStorage.Triggers.getWeaponTool.OnServerInvoke = fetchWeaponModel

Any ideas or thoughts?

Just put them in ReplicatedStorage. It will make things easier for you. You even said it yourself:

Exploiters could also just go through the character of another player with the tool they want and download it that way.

You never invoked the server is why it doesn’t work.

2 Likes