I'm trying to dispense a player an item, but the following function doesn't work. Any ideas why? It would be nice to explain it.
local sandwich = script.Parent["Turkey Sandwich"]
local clicker = script.Parent.ClickDetector
function GiveSandwich(playerWhoClicked)
local players = game:GetService("Players")
local human = players:FindFirstChild(playerWhoClicked.Name)
if human then
print("Successfully Found Player")
local newsandwich = sandwich:Clone()
newsandwich.Parent = human.Backpack
print("Sandwich is dispensed and event completed")
end
end
clicker.MouseClick:Connect(GiveSandwich)

2 comments
You have not included any prints so you it looks like you have done no debugging. Your code also shows that you have not understood what this event passes as an argument. First include some debugging and find out what this script is doing.
After I debugged it with Print, it has shown to debug once I add the name in Line 6. But it still doesn't dispense the Sandwich.