Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Value is a nil value?

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)

2 comments

0

Put them in lightning. I believe it will work better that way.

0

lol put them in the storage place that ROBLOX is trying to depricate?

1 answer

✓ Accepted answer
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

2 comments

0

Oh derp, That's my problem right there. Didn't occur to me that they can't access ServerStorage

1

They also can't access ServerScriptService, but CAN access ReplicatedStorage.

This discussion is preserved as it was. New answers, comments, and votes are closed.