Bug Instance.Name doesn't work

Hey guys!
Today i think i’m in front of a problem.

I’m trying to create an intvalue into plr’s folder wich i created before in the same script.

This is my little script :

	local maxPets = Instance.new("IntValue", Inventory)
	maxPets.Name = "MaxPets"
	maxPets.Value = 30

It creates an intvalue into my folder but it is named “Value”

Why is it not working?

Are you checking the name the moment it is added to your inventory (using a script)? If so, you might want to remove the second argument to new and put maxPets.Parent = Inventory under everything else.

maxPets doesn’t exist yet…
I’m trying to create it with an instance.new

This where I create all my game informations :

game.Players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder",plr)
	leaderstats.Name = "leaderstats"
	
	local acorns = Instance.new("IntValue",leaderstats)
	acorns.Name = "Acorns"
	
	local rebirths = Instance.new("IntValue",leaderstats)
	rebirths.Name = "Rebirths"
	
	local TotalPlrLeaves = Instance.new("IntValue",leaderstats)
	TotalPlrLeaves.Name = "Total leaves"
	
	local plrInf = Instance.new("Folder",plr)
	plrInf.Name = "PlayerInfo"
	
	local leaves = Instance.new("IntValue",plrInf)
	leaves.Name = "Leaves"
	
	local HipSize = Instance.new("IntValue",plrInf)
	HipSize.Name = "HipSize"
	
	local hipLevel = Instance.new("IntValue",plrInf)
	hipLevel.Name = "HipLevel"
	hipLevel.Value = 1
	
	local quest = Instance.new("IntValue",plrInf)
	quest.Name = "Quest"
	quest.Value = 1000
	
	local onTheQuest = Instance.new("IntValue",plrInf)
	onTheQuest.Name = "OnTheQuest"
	
	local playTime = Instance.new("IntValue",leaderstats)
	playTime.Name = "Play time"
	
	local backpackpower = Instance.new("NumberValue",plr)
	backpackpower.Name = "PowerBP"
	
	local equippedTool = Instance.new("StringValue",plr)
	equippedTool.Name = "EquippedTool"
	
	local equippedBP = Instance.new("StringValue",plr)
	equippedBP.Name = "EquippedBackpack"
	
	local equippedPet1 = Instance.new("StringValue", plr)
	equippedPet1.Name = "EquippedPet1"
	equippedPet1.Value = "none"
	
	local equippedPet2 = Instance.new("StringValue", plr)
	equippedPet2.Name = "EquippedPet2"
	equippedPet2.Value = "none"
	
	local highestMap = Instance.new("IntValue", plrInf)
	highestMap.Name = "HighestMap"
	highestMap.Value = 1
	
	local debounceData = Instance.new("Folder",game.ServerStorage.DebounceData)
	debounceData.Name = plr.Name
	
	local Tdebounce = Instance.new("BoolValue",debounceData)
	Tdebounce.Name = "ToolDebounce"
	
	local Pdebounce = Instance.new("BoolValue",game.ReplicatedStorage.DebouncePet)
	Pdebounce.Name = plr.Name
	
	local Cdebounce = Instance.new("BoolValue",game.ReplicatedStorage.DebounceCrate)
	Cdebounce.Name = plr.Name
	
	local TBdebounce = Instance.new("BoolValue",game.ReplicatedStorage.DebounceToolBox)
	TBdebounce.Name = plr.Name
	
	local sellDeb = Instance.new("BoolValue",debounceData)
	sellDeb.Name = "SellDebounce"
	
	local Inventory = Instance.new("Folder",plr)
	Inventory.Name = "Inventory"
	
	local Tools = Instance.new("Folder",Inventory)
	Tools.Name = "Tools"
	
	local Backpacks = Instance.new("Folder",Inventory)
	Backpacks.Name = "Backpacks"
	
	local Pets = Instance.new("Folder",Inventory)
	Pets.Name = "Pets"
	
	local petsNumber = Instance.new("IntValue", Inventory)
	petsNumber.Name = "PetsNumber"
	
	local maxPets = Instance.new("IntValue", Inventory)
	maxPets.Name = "MaxPets"
	maxPets.Value = 30
	
	local toolNumber = Instance.new("IntValue", Inventory)
	toolNumber.Name = "ToolsNumber"
	
	local backpackNumber = Instance.new("IntValue", Inventory)
	backpackNumber.Name = "BackpacksNumber"
	
	local maxSlots = Instance.new("IntValue", Inventory)
	maxPets.Name = "MaxSlots"
	maxSlots.Value = 30
	
	local addAndRemove = script:WaitForChild("Adder/Remover"):Clone()
	addAndRemove.Parent = Inventory
	addAndRemove.Disabled = false
	
	local Up = Instance.new("BoolValue",plr)
	Up.Name = "Up"
	
	local claimed = Instance.new("BoolValue", plr)
	claimed.Name = "Claimed"
	
	local wallFolder = Instance.new("Folder", workspace)
	wallFolder.Name = "WallFolder"..plr.Name
	
	local petSB = Instance.new("NumberValue", plrInf)
	petSB.Name = "PetSpeedBonus"
	petSB.Value = 1
	
	local petLeavesBonus = Instance.new("NumberValue", plrInf)
	petLeavesBonus.Name = "PetLeavesBonus"
	petLeavesBonus.Value = 1
	
	local basicWalkSpeed = Instance.new("IntValue", plrInf)
	basicWalkSpeed.Name = "BasicWalkSpeed"
	basicWalkSpeed.Value = 16

I am aware that you are creating it, but you don’t need to type

local maxPets = Instance.new("IntValue", Inventory)

you can also use

local maxPets = Instance.new("IntValue")
--...
maxPets.Parent = Inventory

to ensure that the code inbetween gets executed before any other script is aware of the value’s existance.

1 Like

this is my inventory:
image

output :

14:32:54.110 - Infinite yield possible on 'Players.Padrox_x.Inventory:WaitForChild("MaxPets")'
14:32:54.111 - Stack Begin
14:32:54.111 - Script 'Players.Padrox_x.PlayerGui.MainGameGUIs.PetInventory.Frame.MainFrame.NumberOfPets.LocalScript', Line 3
14:32:54.112 - Stack End

And my script :

local maxPets = Instance.new("IntValue")
	maxPets.Name = "MaxPets"
	maxPets.Value = 30
	maxPets.Parent = Inventory

It looks the that line

maxPets.Name = "MaxPets"

never ran but I don’t know if it did, try printing around it

print('a')
maxPeta.Name = "MaxPets"
print('b')

Does this output a and b? If not that line never ran thus it never has been set.

This is very strange because I add this line :

print(MaxPets.Name)

and it prints the correct Name.

ANd there is two ways to know if it works.
The awnser is yes it runs because the value is set to “True” and my script is about 5 hundreds lines.
And all those lines run.

So yes it print a and b:
image

Here’s your problem:

local maxSlots = Instance.new("IntValue", Inventory)
maxPets.Name = "MaxSlots"
maxSlots.Value = 30

typo in maxSlots on the second line

1 Like

Oh thx you ! <3

You save me !
I’m stupid sorry x)

I’ve so much things to learn!
If you want to help me more, you can add me on discord : Padrox#8546