How do I get the value of something in a table with the index?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    See title.
  2. What is the issue? Include screenshots / videos if possible!
    It tells me “got nil”. I’m not sure why this is happening; can I not get values this way like I do in Java?
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve looked around on google and DevForum. Somehow, by curse or blessing, I found ZERO posts that actually worked.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local bulb = script.Parent
local proxPrompt = bulb:WaitForChild("ProximityPrompt")
local positions = {
	cframe1 = CFrame.new(-85.089, 9.024, -5.376) * CFrame.Angles(0,0,0),
	cframe2 = CFrame.new(-85.089, 9.018, -14.429) * CFrame.Angles(0,0,0),
	cframe3 = CFrame.new(-95.027, 8.983, -9.867) * CFrame.Angles(0,0,0)
}
proxPrompt.Triggered:Connect(function()
	proxPrompt:Destroy()
	for i=1,3 do
		local truss = Instance.new("TrussPart")
		truss.Size = Vector3.new(2,28,2)
		local cframe = positions[i]
		truss.CFrame = cframe
		truss.Parent = game.Workspace.IntroSequence
	end
end)

That’s the code.
The error message is: Unable to assign property CFrame. CoordinateFrame expected, got nil - Server - Script:14

Specifically these lines:

local cframe = positions[i]
truss.CFrame = cframe

Iterating through your positions table with an in pairs loop can accomplish this for you instead of a for loop.

Additionally, if you’re going to :Destroy() the proximity prompt after it’s been triggered, then I would use the :Once() method to connect your function. That way the .Triggered signal will disconnect itself after it’s been fired.

proxPrompt.Triggered:Once(function() -- Instead of :Connect(), use :Once()
    -- Instead of a for loop, you can do:
    for _, cframe in positions do
        local truss = Instance.new("TrussPart", workspace)
        truss.Size = Vector3.new(2, 28, 2)
        truss.CFrame = cframe
    end
end)

Thank you, this worked. (Sorry for the late response; I was eating) Also, thank you for telling me about the :Once() function, I didn’t even know this existed!

Although I have a question. I want the proximity prompt to be like, completely gone, invisible. Will disabling the prompt after triggering Once work?

Yes, it will work. The :Once() method just disconnects the .Triggered event.

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