Giving Item to Player from ServerStorage Doesn't Work?

I was doing some testing because animations won’t work when they come from ReplicatedStorage, and so I’m using a sword because I thought that would work, it didn’t work, so I tried to put it in ServerStorage, it would give in ReplicatedStorage, but not in ServerStorage, can anyone explain?
Code:
local tool = game.ServerStorage.ClassicSword
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	tool:Clone()
	tool:Clone().Parent= player.Backpack
end)
2 Likes

That is simple. You can not get anything in the ServerStorage from a local script. That is because ServerStorage is on the server side, not the client.

Is it possible with a regular script, with the exact same code, or would you have to make a different script?

You would have to change ways up of getting the player, other then that, the code should work.

The client (I’m assuming it’s being run by one as you’re using LocalPlayer and GUI events) cannot access ServerStorage. ReplicatedStorage can be accessible by both the client and the server, but the client would have to ask the server to clone the sword for them because of filtering. Try sending a remote event! They’re really useful.

First, you’d want to put a RemoteEvent in ReplicatedStorage. It could be in a folder, or just plainly inside of ReplicatedStorage. Now, we get on to the code.

Server:

local event = game.ReplicatedStorage.RemoteEvent -- Path to the RemoteEvent

event.OnClientEvent:Connect(function(plr)
    game.ServerStorage.ClassicSword:Clone().Parent = plr.Backpack
end)

Client:

local event = game.ReplicatedStorage.RemoteEvent

script.Parent.MouseButton1Click:Connect(function()
    event:FireServer()
end)

If you run into any issues using this let me know.

1 Like

This one requires a remote event for the client because as tnt_Dante stated earlier, ServerStorage is on the server-side.

Local Script for Client:

script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.GiveToolEvent:FireServer()
end)

Server Script in ServerScriptService:

local tool = game.ServerStorage.ClassicSword

local GiveTool = game.ReplicatedStorage.GiveToolEvent --- remote event in ReplicatedStorage

GiveTool.OnServerEvent:Connect(function(player)
    tool:Clone().Parent = player.Backpack
end)