Problems with GUI tool giver

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)

Here is the output.


Any kind of help is welcome.

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

1 Like

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

1 Like

Heres a whole working code for you:

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)
1 Like

i tried to make it so it checks if player already has that tool, but if its errors just remove the existingTool thing

1 Like

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.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.