Need Help Understanding This Parameter

So im currently trying to understand the fundimentals of lua through the Roblox documations and i need help understanding how this “otherpart” parameter works.

local speedBoost = script.Parent

local function onTouch (otherpart)
	local character = otherpart.Parent
	local humanoid = character:FindFirstChildWhichIsA("Humanoid")
	if humanoid and humanoid.WalkSpeed <= 50 then
		humanoid.WalkSpeed += 10
		speedBoost.CanTouch = false
		speedBoost.CanTouch = true


so speedBoost.Touched is “fired” when something touches it. the object that touches it is the “otherPart” in this case.

so if my leg touches the speed boost, my leg is considered the “otherPart”

you can rename “otherPart” to whatever you want. i usually do:

local function touched(Part)
    print("PartA was touched by " .. Part.Name)



this script works by waiting until a part touches the speed bost. since your roblox character is made up of parts, it’s parent (the model) is then found. since all character models have a humanoid (unless u make ur own but thats not relevant), it finds the humanoid and applies a speed boost to it.

the CanTouch is a property that prevents .Touched from firing. if you disable CanTouch, it won’t be able to fire. this way you won’t immediately get up to 50+ walkspeed without doing it 5 times which would take 5 seconds.

edit 2:
all parameters can be renamed. so its best to focus on what actually is sent. you can do this by clicking once on the “onTouch” word in the speedBoost.Touched:Connect(onTouch) line. it should show something that says like Connect(func: (part: BasePart)...etc. the class after the colon, in this case “BasePart”, is the object being given in the parameter.

(may not be BasePart, it may say Instance but u get the point! goodluck learning and have fun!)

When you connect the touched event of a base part to a function, the otherPart parameter is just simply the part that touched the part you are listening to the touch events on. In this case, they are checking to see if a character with a humanoid touched the speedboost. For example, if your character’s hand touched the part, the Touched event would pass the character’s hand as the otherpart variable.

You can find some more information, and a better explanation than I can give about this on the documentation.

Well uhh BaseParts have Touched RBXScriptSignal (Commonly known as Events) You can Connect this Event to a function. This event will give the otherPart parameter, which is the object that touched your basePart. Let’s say we have Part A and Part B. Part A has a script with the Touched event connected to a function. If Part B touches Part A then the Touched event will fire and otherPart will be Part B, as Part B touched Part A (I hope you understood lol)

Okay wait does that mean the parameter changes because the function is conntected to a event? Like its not like a normal one that is not connected to a event?

Well I don’t exacty know what you mean but otherPart is the BasePart that touched the Part with the Touched event. The touched event fires when the part is touched, so you can connect it to a function and the otherPart param is the part that touched it. But it is not constantly checking what’s touching it, for that you’d need a while true do loop. It just fires when the part is touched.