Attempt to index function with Enabled

This is a local script In starterplayerscripts the purpose of it is to enabled and disable proximity prompts. In the script I am getting an error for Enabled on the second line where I Enabled A proximity prompt to true. I already have tried to debug and check to make sure boothModel.Part.Remove.Enabled exists. And it does. So why is Enabled being thought as a function? attempt to index function with ‘Enabled’ How can I fix this?

Local script:

game.ReplicatedStorage.Events.LR2024.OnClientEvent:Connect(function(Booths)
	local player = game.Players.LocalPlayer
	local Stand = game.Workspace.Stands:FindFirstChild(player.Name)
	local folder1 = Stand.Booth
	local folder2 = Stand.Booth1
	local folder3 = Stand.Booth2
	local boothModel = folder1:FindFirstChild(Booths) or folder2:FindFirstChild(Booths) or folder3:FindFirstChild(Booths)
	if boothmodel then
		boothModel.Part.OwnerPrompt.Enabled = false
		boothModel.Part.Remove.Enabled = true --error on this line??

	end
	
end)

That’s because Instance.Remove is a function inherited from the Instance class. When called, it will parent the instance to nil.

Instance:Remove() --parents whatever instance is to nil and does so for all it's descendants

So, it’s to do with the way Luau tries to find what you mean.

Step 1 - search the properties and methods of the instance
Step 2 - if no match, search the instance’s children
Step 3 - nothing found, throw an error

So, it reaches step 1, finds the Remove method, and then returns that method and does not reach Step 2, which is actually where you want it to reach. This can be fixed by renaming the prompt or using :FindFirstChild() instead of indexing the child.

1 Like

This fixed the problem thank you!!

1 Like

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