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

attempt to index upvalue?

I was wondering what this meant. I have absolutely no clue.

local part = script.Parent.Model:GetChildren()
local open1 = script.Parent.Sens -- The part that will turn to face Part2
local open2 = script.Parent.Sens2
local origin = script.Parent.Sens3
local sensor1 = script.Parent.Sensor1
local sensor2 = script.Parent.Sensor2

--Opening from interior
function open1()
	part.BodyGyro.cframe = CFrame.new(part.Position, open2.Position)
	wait(5)
	part.BodyGyro.cframe = CFrame.new(part.Position, origin.Position)
end

--Opening from exterior
function open2()
	part.BodyGyro.cframe = CFrame.new(part.Position, open1.Position)
	wait(5)
	part.BodyGyro.cframe = CFrame.new(part.Position, origin.Position)
end

sensor1.Touched:connect(open1)
sensor2.Touched:connect(open2)

15:53:00.390 - Workspace.Model.Script:10: attempt to index upvalue 'open2' (a function value)

15:53:00.391 - Stack Begin

15:53:00.393 - Script 'Workspace.Model.Script', Line 10

15:53:00.394 - Stack End

Source: http://wiki.roblox.com/index.php?title=API:Class/BodyGyro

1 comment

0

Your error is you have to variables named the same thing. Obviously this isn't the answer you're looking for. I don't really know what an up value is. But that's your error :P

2 answers

✓ Accepted answer
local open1 = script.Parent.Sens

function open1()

Your variable is the same name as your function. Since the function is created later, it will override the name of the variable. So now open1 and open2 refer only to the functions.

Just change some of the names and you should be fine.

The problem is because you overwrote your open2 variable with a function. You'll need to use different variable names for your functions than other variables that you plan to use within them.

local part = script.Parent.Model:GetChildren()
local open1 = script.Parent.Sens -- The part that will turn to face Part2
local open2 = script.Parent.Sens2
local origin = script.Parent.Sens3
local sensor1 = script.Parent.Sensor1
local sensor2 = script.Parent.Sensor2

--Opening from interior
function touch1()
    part.BodyGyro.cframe = CFrame.new(part.Position, open2.Position)
    wait(5)
    part.BodyGyro.cframe = CFrame.new(part.Position, origin.Position)
end

--Opening from exterior
function touch2()
    part.BodyGyro.cframe = CFrame.new(part.Position, open1.Position)
    wait(5)
    part.BodyGyro.cframe = CFrame.new(part.Position, origin.Position)
end

sensor1.Touched:connect(touch1)
sensor2.Touched:connect(touch2)

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