Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why doesn't this script physically change the part its accessing?

local animS = script.Parent.Size
local animP = script.Parent.Position
local blinkspeed = .01
local eyewidth = 100
local rateLP = Vector3.new((blinkspeed+-1), 0, 0)
local rateRP = Vector3.new(blinkspeed, 0, 0)
local rate = Vector3.new(blinkspeed, 0, 0)
while wait() do
	if script.Parent.Name == "RightBlinkAnimation" then
		for i = 0, eyewidth do
			wait()
			animP = animP+rateRP
			animS = animS+rate
		end
		for i = 0, eyewidth do
			wait()
			animP = animP-rateLP
			animS = animS-rate
		end
	elseif script.Parent.Name == "LeftBlinkAnimation" then
		for i = 0, eyewidth do
			wait()
			animP = animP+rateLP
			animS = animS+rate
		end
		for i = 0, eyewidth do
			wait()
			animP = animP-rateLP
			animS = animS-rate
		end
	end
end

Inbetween line 13 and 14 I did a print for animP and animS and it showed it was changing in the print but upon viewing the part it was static and was not changing size or position..

1 answer

I think you're misunderstanding that accessing an object's property and saving to a variable does not give you a reference to that property. Instead, it just copies what that property was set to when it was accessed. If you want to set the property of a part, you have to do so directly. See my example below:

local name = game.Workspace.Baseplate.Name
print(game.Workspace.Baseplate.Name) --> "Baseplate"
print(name) --> "Baseplate"

name = "NewName"
print(game.Workspace.Baseplate.Name) --> "Baseplate"
print(name) --> "NewName"

game.Workspace.Baseplate.Name = name
print(game.Workspace.Baseplate.Name) --> "NewName"
print(name) --> "NewName"

name = "AnotherNewName"
print(game.Workspace.Baseplate.Name) --> "NewName"
print(name) --> "AnotherNewName"

This discussion is preserved as it was. New answers, comments, and votes are closed.