Hello
I have been trying to make a GUI button that will spawn tools into the players hand when clicked. However, i don't know how to find the player that clicked the button (so that the object can be cloned into their inventory). This is what i have done so far.
local coffee = game.ReplicatedStorage.Food.Coffee local button = script.Parent button.MouseButton1Down:Connect(function() end)
Thanks!
What you want to do like what @notoriousNoah10 said is create a RemoteEvent into ReplicatedStorage. Then rename it to something like "EquipItem"
Then in a LocalScript inside of your button do:
local coffee = game.ReplicatedStorage.Food.Coffee local button = script.Parent button.MouseButton1Down:Connect(function() game.ReplicatedStorage.EquipItem:FireServer(coffee) end)
And now in a server script do:
game.ReplicatedStorage.EquipItem.OnServerEvent:Connect(function(player, item) local clone = item:Clone() clone.Parent = player.Backpack player.Character:WaitForChild("Humanoid"):EquipTool(clone) end)
Edit: Fixed a typo in the code Tested it and it works.
You're better off using a RemoteEvent for cloning the tool as doing it from a LocalScript will result in replication issues such as the tool not working properly