Anyone help me understand this?

Yo Im really confused just by looking at this script and I was wondering if anyone can help me try and help me understand this and whats going on. Especially with the value[1], value[2], value[3]. How does that work???

local tool=script.Parent
local handle=tool.Handle

local remotefunction=tool.RemoteFunction
local debris=game:GetService("Debris")

function remotefunction.OnServerInvoke(player,command,value)
	if command=="protect" then
		if value[2] then
			local currentvest=value[1]:FindFirstChild("VestArmour")
			if currentvest then
				currentvest:Destroy()
			end
			local vest=Instance.new("Hat")
			vest.Name="VestArmour"
			handle:Clone().Parent=vest
			vest.AttachmentPos=Vector3.new(0,2,0.05)
			vest.Parent=value[1]
			local ratio=value[2].Health/value[2].MaxHealth
			value[2].MaxHealth=100+value[3]
			value[2].Health=(100+value[3])*ratio
			
			tool.Handle.Transparency=1
			wait(2)
			tool.Handle.Transparency=0
		end
	end
end
1 Like

In this script “Value” is a table, and like any table you can index it like this table[1]. The number or thing in brackets is the key, what is outputted is the value. Here’s an example of what that does on arrays.

local Array = {"Dogs", "Animals", "Cats", "Sandwhich"}

print(Array[1]) -- Would print "Dogs" 

Here’s what it does on dictionaries:

local Dictionary = {
This = "Dogs", 
That = "Cats", 
TheThird = "Animal"
}

print(Dictionary[This]) -- Prints "Dogs"

Here is documentation on dictionaries and arrays:
Arrays and Dictionaries | Documentation - Roblox Creator Hub

So if the value was value[1] it would be the player? and if value[2] it would be command so on so forth?

function remotefunction.OnServerInvoke(player,command,value)

What do you mean? Value is a table, player and command are variables sent from the remoteFunction. It also depends on what is actually written inside of the table, you can only get values from inside the table indexing a table.

1 Like

But I dont see any tables? Where is the value pulling stuff from?

Value is the variable for this table.

local Value = {"Stuff inside of a table"}

So instead of writing out the whole table over and over again you can refer to it with the variable you set it to, which in this case is value.

1 Like