Hello there!
I’m looking forward to script a GUI where you can pick a tool and it goes to your backpack, although it’s not working… whenever I click the button the tool won’t be given to me.
script.Parent.MouseButton1Click:Connect(function(player)
local folder = game.ServerStorage:FindFirstChild("RegularCups")
local cup = folder:FindFirstChild("Grande Cup"):Clone()
cup.Parent = player.Backpack
end)
GUI’s must be handled through the client and passing tools to the players backpack must be done through the server, meaning you will need a remote event. RemoteEvent | Roblox Creator Documentation
your “player” is set to nil, i think that function doesnt give a player, since guis needs to be scripted from client, and u can just get the player from game.Players.LocalPlayer
First, place a RemoteEvent in replicatedstorage and name it for example “Tool”.
Then make a server sided script:
game.ReplicatedStorage.Tool.OnServerEvent:Connect(function(plr,tool)
local existingTool = plr.Backpack:FindFirstChild(tool.Name) or plr.Character:FindFirstChild(tool.Name)
if not existingTool then
local newTool = tool:Clone()
newTool.Parent = plr.Backpack
end
end)
And lastly a client sided script in the button:
local folder = game.ServerStorage:FindFirstChild("RegularCups")
local cup = folder:FindFirstChild("Grande Cup")
script.Parent.MouseButton1Click:Connect(function()
game.ReplicatedStorage.Tool:FireServer(cup)
end)
Hello, your script returned this error: 22:17:21.252 RegularCups is not a valid member of ServerStorage "ServerStorage" - Client - LocalScript:1. You forgot that local scripts can’t access ServerStorage.