Instance.new not creating the new instance

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make a new IntValue
  2. What is the issue? Include screenshots / videos if possible!
    When I use the Intstance.new function, it doesn’t create the new instance for some reason
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried changing the classname and setting the parent
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
identity = Instance.new("IntValue")
identity.Name = "identification"
identity.Parent = game.Workspace

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

What context is this code running in? The code you’ve shared should work fine.

1 Like

this script’s runcontext is legacy

it works for me, make sure that the code run, that all I can tell you

Sorry - I meant what environment the script is running in. Is it a LocalScript, a Script, or something else?

ohh sry, its a script, not a localscript

yes, the code runs, i put a print after the lines of code i showed, and the print does run, so im not sure what the problem is

Where is the script parented to?

local identity = Instance.new("IntValue")
identity.Name = "identification"
identity.Parent = game:GetService("Workspace")

probably does the same thing but try it anyway

Ooh! That could be the reason. He might’ve renamed the workspace.

identity = Instance.new("IntValue")
if identity then
	identity.Name = "identification"
	identity.Parent = workspace
else
	print("identity wasnt created")
end

Roblox already references workspace, it’s better than using game.Workspace or GetService, and added a quick debug.

Try renaming the script to something else. Sometime some scripts collide with roblox scripts. Like once I tried making a camera script and I named it “CameraScript” which is apparently used by roblos

this script is parented to a tool

just tried this, but still doesnt seem to work, no error msg given either

i tried this too, but it still doesn’t create the new intvalue and also doesnt print “identity wasnt created”

please provide the code of your tool

just renamed it, but the intvalue still isnt being created

here’s the code for the script

identity = Instance.new("IntValue")
if identity then
	identity.Name = "identification"
	identity.Parent = workspace
else
	print("identity wasnt created")
end
print("identity created")

It’s either that your studio may be bugged and the explorer is just not showing you the IntValue that was just created, or this post is a troll. I honestly can’t think of any other reasons why this wouldn’t work.

Could you try this? Does this print Workspace.identification or no? If it prints the first one, the object was created.

identity = Instance.new("IntValue")
if identity then
    identity.Name = "identification"
    identity.Parent = workspace
    print(identity:GetFullName())
else
    print("no")
end

That if statement is reductive. If that Instance call fails for some reason, it will throw an error, and the rest of the script will terminate anyways. If you really need to catch a possible error, use pcall. You are guaranteed to have the created instance since IntValue is a valid class name.

Just use the following:

identity = Instance.new("IntValue")
identity.Name = "identification"
identity.Parent = workspace

You need to show us the entire script. It may be possible that execution is not reaching this part of the code.