Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited by DeceptiveCaster 4 years ago
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

0
Rebirtho lmao now i tihnk of it i hate this name Cyrellejheff 11 — 4y
0
I put the code into a code block. DeceptiveCaster 3761 — 4y
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 :) Cyrakohl 108 — 4y
0
It fit into a comment so why don't you post a comment User#24403 69 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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

lua object:method(...)

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

lua object.method(object, ...)

You can index for a function without calling it aswell.

```lua 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."

Ad

Answer this question