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

ServerScriptService.Rebirtho:3: attempt to index field 'Remove' (a function value)?

game.ReplicatedStorage.Remotes.Remove.OnServerEvent:Connect(function(player)
    local ds = game:GetService("DataStoreService"):GetDataStore("ToolSave")
	local key = "id-"..player.userId
 	local tools = ds:GetAsync(key)
	ds:SetAsync("Key", nil)
end)

Heres my script i dont know whats happening but it says ServerScriptService.Rebirtho:3: attempt to index field 'Remove' (a function value)

what does this mean

4 comments

0

Rebirtho lmao now i tihnk of it i hate this name

0

I put the code into a code block.

0

It's because removed is a reserved value for the Remove() function just like other Functions and Properties.

For example let's say you have a Text box that you want Player Names to be inputted into if you call that Textbox "Name" you cannot index it as it's a reserved value for the purpose of the property "Name".

Hopefully this made sense :)

0

It fit into a comment so why don't you post a comment

1 answer

✓ Accepted answer

Properties, events, methods precede children.

So if you have a child with the same name as one of the three, you will be accessing the property/event/method instead.

Instance:Remove is a deprecated roblox function. It isn't completely gone though, you can still use it, though it is encouraged to avoid deprecated items.

Remember that

object:method(...)

Is just syntactic sugar (a nicer way to write something) for this:

object.method(object, ...)

You can index for a function without calling it aswell.

local random = math.random; --// `random` variable contains the math.random function, we indexed for it, we didn't call it

print(random(5, 10)); --> 7

local part = Instance.new("Part");
part.BrickColor = BrickColor.new("Really red");
part.Parent = game:GetService("Workspace");

local part2 = Instance.new("Part");
part2.Parent = part.Parent;
part.Clone(part2).Parent = part.Parent;
--// part2 gets cloned since in `object.method(object, ...)` object is part2

Basically, Lua thought you were trying to index for the Remove function.

The solution is to rename it to something like Delete, but anything that is not "reserved."

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