So I just typed up a script that is supposed to detect when a character is within a certain distance from a part, then prompt the user to interact. What I'm having trouble with is getting the script to detect one of the parts in the workspace by using a table. Here's the code:
local player = game.Players.LocalPlayer
local char = player.Character
local mouse = player:GetMouse()
local cam = workspace.CurrentCamera
local Detectables = workspace:WaitForChild("Detectables")
local ObjectDetected = false
local DetectedObject
local DetectableObjs = {}
for _, v in pairs(Detectables:GetChildren()) do
table.insert(DetectableObjs, v)
end
game:GetService('RunService').RenderStepped:connect(function()
if (char:WaitForChild("Torso").Position - workspace:WaitForChild(DetectableObjs.Name).Position).magnitude <= 10 then
player.PlayerGui:WaitForChild("Interact"):WaitForChild("Frame").Visible = true
elseif (char:WaitForChild("Torso").Position - workspace:WaitForChild(DetectableObjs.Name).Position).magnitude > 10 then
player.PlayerGui:WaitForChild("Interact"):WaitForChild("Frame").Visible = false
end
end)
mouse.KeyDown:connect(function(Key)
if Key == "f" and ObjectDetected then
DetectedObject.Parent = player.Backpack
ObjectDetected = false
ObjectDetected = nil
end
I keep getting the error: Argument 1 missing or nil

3 comments
I'm new at scripting, but, you didn't define DetectedObject at line 8. Unless, that is supposed to be like that. I'll just make that a wild guess.
DetectedObject is supposed to be nil until a part that's defined in the table is found in the workspace.
You don't need to assign variables a value when you define them, so it works. What line is the error on?