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

Why does it print as nil value?

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

2 comments

0

What class is NoOfItems? Are you sure it is a value class? Print the classname of it to make sure.

0

when i print it says NumberValue

1 answer

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!

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