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

Why does it print as nil value?

Asked by 6 years ago

It says NoOfItems is a nil value? Btw this is Tuneable's placement script but changed to fit my game

local script:

local function initiatePlacement(itemName)  
    script.Parent.HitboxHandler.Disabled = true
    placementEnabled = true
    NoOfItems = player.PlayerItems:FindFirstChild(itemName)


        game:GetService("UserInputService").InputBegan:connect(function(input)
            if input.KeyCode == Enum.KeyCode.X then
                cancelPlacement()
            end
        end)
    if NoOfItems.Value <= 0 then
        cancelPlacement()
        player.PlayerItems.PreviousItem.Value = ''
    end
    cancelPlacement()
    dummyModel = GameItems[itemName]:Clone()
    currentItemName = itemName
    for _, object in pairs(dummyModel:GetChildren()) do
        if (object:IsA("BasePart")) then
            object.CanCollide = false
        end
    end
    dummyModel.Parent = workspace
    local signal = plane:enable(dummyModel)
    signal:connect(function(location, _)
        game:GetService("ReplicatedStorage").PlaceItem:FireServer(currentItemName, location)
        player.PlayerItems.PreviousItem.Value = itemName            
        if NoOfItems.Value <= 0 then
            cancelPlacement()
        end 
    end)
end

game:GetService("ReplicatedStorage").MoveItem.OnClientEvent:connect(function(player)
    print('Recieved')
    print(game.Players.LocalPlayer.PlayerItems.PreviousItem.Value)
    initiatePlacement(GameItems:FindFirstChild(game.Players.LocalPlayer.PlayerItems.PreviousItem.Value))
end)

PlayerItems is a folder with a list of number values each value has a different name PreviousItem is string value

Output:

Recieved
BasicFurnace
16:50:46.975 - Players.therealae.PlayerGui.TestGui.ClientPlacement:46: attempt to index upvalue 'NoOfItems' (a nil value)
16:50:46.975 - Stack Begin
16:50:46.983 - Script 'Players.therealae.PlayerGui.TestGui.ClientPlacement', Line 12 - upvalue initiatePlacement
16:50:46.984 - Script 'Players.therealae.PlayerGui.TestGui.ClientPlacement', Line 38
16:50:46.985 - Stack End
0
What class is NoOfItems? Are you sure it is a value class? Print the classname of it to make sure. UgOsMiLy 1074 — 6y
0
when i print it says NumberValue therealae 7 — 6y

1 answer

Log in to vote
0
Answered by
OfcPedroo 396 Moderation Voter
6 years ago

It states as nil because there is no such directory called

player.PlayerItems:FindFirstChild(itemName)

What you want is

player.Backpack:FindFirstChild(itemName)

If this solved your problem, please mark as the solution!

As always, good scripting!

Ad

Answer this question