New to scripting why does properties change code not work

i’m new to scripting in lua and this wont work. im trying to get part, part2, and part3 to all change their anchored to false and transparency to 1, chronologically. this is my code, can you help me fix it please

function PropertiesChange(Block)
	local part = game.Workspace.Block
	part.Anchored = false
	part.Transparency = 1
end

PropertiesChange(Part)

task.wait(3)

PropertiesChange(Part2)

task.wait(3)

PropertiesChange(Part3)

You never use the Block argument anywhere in your code.

1 Like
function PropertiesChange(Block)
	Block.Anchored = false
	Block.Transparency = 1
end

Imagine you have two people with the last name Doe in the room. If you start saying “Hey John Doe!” You’re not going to be talking to John Jane Doe. You’re going to be talking to John Doe.

The moment you say “Hey game.Workspace.Block!” You’re not going to be talking to game.Workspace.Part, you’re going to be talking to game.Workspace.Block.

So to fix your problem, just talk to the block you nicknamed Block instead, then, when calling the function, specify which block you’re talking about by saying their full name.

function PropertiesChange(block)
	block.Anchored = false
	block.Transparency = 1
end

PropertiesChange(game.Workspace.Part)

task.wait(3)

PropertiesChange(game.Workspace.Part2)

task.wait(3)

PropertiesChange(game.Workspace.Part3)
1 Like

The Block argument you passed into PropertiesChanged isn’t being used, you’re indexing a different part

function PropertiesChange(Block)
      Block.Anchored = false
      Block.Transparency = 1
end

thanks!
for parameters i thought it would replace any wording “Block” in the code with “Part” or “Part2” or “Part3”.
is my understanding flawed?

No problem. A bit, yes. When you define a variable or a parameter, all you’re really doing is making a new ‘name’ for something. game itself is a name.

So when you say game.something all you’re really saying is: “The thing named ‘something’ inside of ‘game’”, notice that ‘something’ is always ‘something’, even if you named a variable ‘something’ previously.

There is a way to do what you’re trying to do using [], like so:

local Block = "Part1"

-- This is always the thing named 'Block' inside of the thing named 'Workspace' inside of the thing named 'game'
game.Workspace.Block

-- This is the thing named whatever 'Block' is ("Part1"), inside of the thing named 'Workspace' inside of the thing named 'game'
game.Workspace[Block]

-- And it's equivalent to this:
game.Workspace.Part1
1 Like

thank you so much! i understand it

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.