Adding a new part through scripting

  1. What do you want to achieve? Keep it simple and clear!
    I want to achieve adding a part from scripting, when I play the game the part spawns with 0.5 transparency.

  2. What is the issue? Include screenshots / videos if possible!
    When I enter this code it does not work:

local Part = Instance.new(“Part”)
Part.Parent = game.Workspace
Part.Transparency = 0.5

I am learning scripting, and I was watching this video,

Go to [03:38] | nil, to see the part I was on.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Tried watching other videos, and redoing the code.
1 Like

The code you sent above looks like it should work. Maybe you just forgot to set the position?

local part = Instance.new("Part", workspace)
part.Transparency = 0.5
part.Anchored = true
part.CFrame = CFrame.new(Vector3.zero)

Where is this script in the Explorer? Is it a LocalScript or a normal Script?

true.the script should work.i think part’s position is different.

The script is a normal script inside another part called PinkPart, inside of Workspace. In your script you added part.CFrame = CFrame.new(Vector3.zero), but it was never put in the video i put above, and it worked perfectly fine for him without your added line.

Also because I want to follow the tutorial and get what is going on I shoulden’t add other script in it then his.

I might be wrong, but Vector3.Zero is for Position. Not CFrame. So maybe put
Part.Position
and not
CFrame
?

I asked ChatGPT cause I don’t know, but it told me to enter this code:

local Part = Instance.new(“Part”)
Part.Parent = game.Workspace
Part.Transparency = 0.5
Part.Size = Vector3.new(4, 1.2, 2) – Default size, but explicitly set for clarity.
Part.Position = Vector3.new(0, 50, 0) – Position the part 50 studs above the origin to make it easily visible.
print(“Part created”) – Confirm in output that the script ran.

I entered it and it worked however I want it to work with the code I put it in at the beginning for my example, it’s supposed to work according to the tutorial, but why isin’t the code working?

What do you mean part’s position is different?

once you spawn the part.the position might be random.

Could you please share a screenshot of your Explorer window? The component may have been created, but it might be obscured by the default SpawnLocation or another element.