I just made a "Dig" tool that, when the player clicks on certain parts, it gives him the item from ServerStorage
that a Value in the part names. I've tried a StringValue
to search for the item by name, and ObjectValue
to link directly to the item, but both cases give me the same error saying that it's attempting to index a nil value. Here's the block in question:
function clicked() if mouse.Target == nil then return end --mouse is defined earlier if equip == false then return end -- T/F variable defined earlier if mouse.Target.Name == "dgSpot" then local tlname = mouse.Target.Tool.Value -- Line below is for StringValue --local tool = game.ServerStorage:FindFirstChild(tlname):Clone() -- Line below is for ObjectValue local tool = tlname:Clone() tool.Parent = player.Backpack end end mouse.Button1Down:connect(clicked)
function clicked() if mouse.Target == nil then return end --mouse is defined earlier if equip == false then return end -- T/F variable defined earlier if mouse.Target.Name == "dgSpot" then local tlname = mouse.Target:findFirstChild"Tool" if tlname then tlname = tlname.Value else return end -- Line below is for StringValue --local tool = game.ServerStorage:FindFirstChild(tlname):Clone() -- Line below is for ObjectValue local tool = tlname:Clone() tool.Parent = player.Backpack end end mouse.Button1Down:connect(clicked)
oh btw if this is in a localscript it cant access serverstorage