How do I store a tool with a server script in it that can be accessed by the client?

I have a tool in replicated storage, and when the game starts the tool will be cloned from the replicated storage into the local player’s backpack (If they bought a gamepass.)

The only problem is, the tool doesn’t work because the tool has server scripts inside of it. I can’t store the tool in server storage because then the client can’t access it. I can’t store it in the workspace because then you could physically see it. Where can I store the tool?

I don’t understand the problem. Tools can have server-side scripts —they need server-side scripts if the tool is meant to affect other players and/or the game world.

Is issue about the clients not being able to see the tool or is it due to the fact that the server scripts inside the tool aren’t working?

The tool needs a server script to play whenever the player actually uses it, but I need a local script to copy it into the player’s backpack from the replicated storage. It’s just server scripts can’t be stored in replicated storage.

The local script successfully copies it into the player’s backpack, but the tool doesn’t work because the server script inside of it can’t be in replicated storage.

… But server-side scripts CAN be stored in ReplicatedStorage. ReplicatedStorage is replicated to both the server and clients, that’s why it’s called ReplicatedStorage.

Then in the case you need a Server Script that manages giving the tool to the player when they join. What you can do is insert a script in the ServerScriptService and from there you can manually make the tool clone to the players backpack when the player joins.

Try giving the tool from a Server Script and not a LocalScript

Well I can’t get the local player from a server script

Edit: Oh wait I’ll try using the player added event

You should be able to use replicatedstorage in this scenario. If the tool isn’t working after being cloned from replicatedstorage, then it’s a problem with the tool code. Another place you could store it however, is serverstorage, but that’s only if you’re worried about exploiters seeing the tools in replicatedstorage. You would be able to access the serverstorage from the client by firing a remote event to have a server script clone the tool from serverstorage into the desired player’s backpack.

Yes, use the player added event.
There’s no local player for the server, it’s the server.

Please read threads on the API beforehand: Players | Roblox Creator Documentation

Something like this should do the trick.

game:GetService("Players").PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		--Give tool to player
	end)
end)

Thanks! It worked when I stored the tools in server storage and used a server script to clone them!