Error: "Attempt to index function with (remote event)

  1. What do you want to achieve?
    Whenever you press e it destroys the model

  2. What is the issue?
    Keep getting this error:
    image

  3. What solutions have you tried so far?
    I tried switching to a remote function but it came up with the same error. I looked it up too but didn’t find anything useful.

Local Script:

local remoteE = script:WaitForChild("ToLocal")
local player = game.Players.LocalPlayer
local uis = game:GetService("UserInputService")
local readyForInput = false
local model = nil

remoteE.OnClientEvent:Connect(function(signal, newModel)
	if signal == "touched" then
		readyForInput = true
		model = newModel
	elseif signal == "touchedEnd" then
		readyForInput = false
		model = nil
	end
end)

uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E then
		if readyForInput and model ~= nil then
			model.Flower.Destroy.SignalDestroy:FireServer()
		end
	end
end)

Script to Destroy the part:

script.SignalDestroy.OnServerEvent:Connect(function()
	script.Parent.Parent.Parent:Destroy()
end)

image

Not sure if this is useful but this is the server-side of making the E gui appear:

wait(1)

local range = script.Parent.Parent.Parent.Range
local bill = script.Parent
local playerS = game:GetService("Players")

range.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if hit.Name == "RightFoot" then
			local char = hit.Parent
			local player = playerS:GetPlayerFromCharacter(char)
			char.Appear.ToLocal:FireClient(player,"touched", script.Parent.Parent.Parent)
			bill.Enabled = true
		end
	end
end)

range.TouchEnded:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if hit.Name == "RightFoot" then
			local char = hit.Parent
			local player = playerS:GetPlayerFromCharacter(char)
			char.Appear.ToLocal:FireClient(player,"touchedEnd", script.Parent.Parent.Parent)
			bill.Enabled = false
		end
	end
end)

Looks like the error is coming from this line (or roughly).

I might be wrong, but I think Lua thinks that you are trying to index the :Destroy() function that would destroy the script. Could you try renaming the script to something else (like DestroyScript)?

Other than that, I see no problems.

2 Likes