GUI LocalScript creating a meshpart only working once

Before I start with this I want to let the reader know I am a very beginner scripter.

So basically I created a text button with a localScript inside and the local script creates a part, and adds a mesh to it. Everything works fine the first time but the second time the output says “Attempting to call a nil value” and does not spawn the part + mesh. Any ideas?

Scripts + Output:


For the last pic I clicked twice, the first time it worked the second time it didn’t.


local part ="Part", workspace)

part.Size, part.Name =,4,5), "nana"

local mesh ="SpecialMesh", part)

mesh.Scale, mesh.MeshId =,5,5), "REPLACE THIS"


Maybe this will work

1 Like

Why is your function inside something that requires the function because that function only exists in that if statement and that if statement cant see inside itself and the 16th line cant see inside that if statement

Im also a beginner scripter but i have done a few things in studio and i learned a month ago

I’m pretty sure it is because system does not read the function until the textbutton is clicked. it reads the entire script before starting the function

It worked! Thank you! I honestly wondered what was wrong with the script, I guess I worded it wrong?

I just reworded it and made the code shorter. Mark me as solution if your issue is solved

You need to reference"Part").

You can create a variable for it via
local part =“Part”)