Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Value is a nil value?

Asked by 10 years ago

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)
0
Put them in lightning. I believe it will work better that way. lomo0987 250 — 10y
0
lol put them in the storage place that ROBLOX is trying to depricate? deaththerapy 60 — 10y

1 answer

Log in to vote
1
Answered by
wazap 100
10 years ago
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

0
Oh derp, That's my problem right there. Didn't occur to me that they can't access ServerStorage deaththerapy 60 — 10y
1
They also can't access ServerScriptService, but CAN access ReplicatedStorage. Maxomega3 106 — 10y
Ad

Answer this question