Hiya, I’m trying to make it so at the click of a GUI, the player get’s given a tool that’s located in ServerStorage. I’ve looked at other topics on things similar however nothing has helped me and I keep getting the same error.
Script:
script.Parent.MouseButton1Click:Connect(function()
local backpack = player:WaitForChild("Backpack")
local cloneValue = game.ServerStorage.Value:Clone()
cloneValue.Parent = backpack
end
Any help would be appreciated.
Thanks for your time.
Your mistake is that you’re calling the function from a LocalScript inside the player but players can’t access the ServerStorage. So you basically must put the tool into ReplicatedStorage or you do this with RemoteFunctions and a Script inside ServerScriptService because a ServerScript inside ServerScriptService can access the ServerStorage.
I believe you have to get the tool from an area other than the Server Storage. Instead, try putting the tool inside the replicated storage or lighting. But that’s not all, you also have to look into remote events since Gui buttons only work on the client-side.
The script is located in a part in the Workspace. Would that make a difference?
Make sure the script stays with the player to keep from any random errors happening. Also, make sure to have the script as a Local script, otherwise the button won’t work.