I want to make an item spawn into the player's backpack when I touch a specific block, but when I touch it, it doesn't give me the tool. What am I doing wrong?
local plr = game.Players.LocalPlayer script.Parent.Touched:connect(function() local gravity = game.ReplicatedStorage:WaitForChild("GravityCoil") gravity:Clone().Parent = plr.Backpack end)
First off, it's important to know that LocalPlayer only runs in a LocalScript, and LocalScript is limited in where it can be used, compared to a server Script:
For more info and reference: http://wiki.roblox.com/index.php?title=API:Class/LocalScript
Second, in order to clone a tool to a player's backpack, you need to access that specific player's Character:
script.Parent.Touched:Connect(function(hit) -- Detects if the part that 'hit' the brick contains a Humanoid if hit.Parent.Humanoid then -- Function GetPlayerFromCharacter returns the Character associated with the player (hit.Parent) plr = game.Players:GetPlayerFromCharacter(hit.Parent) -- Clones tool into player's backpack local gravity = game.ReplicatedStorage.GravityCoil:Clone() gravity.Parent = plr.Backpack end end)
Hopefully this helps.