What does (object) do?

Hello, I am making a script that will make you collect coins. In the script, I thought using “givegold(object)” would help but I don’t know what (object) means. Yes, I am doing this in a module script because I don’t know how to implement this into my regular script. Any help appreciated.

local FunctionModule = {}



function FunctionModule.givegold(object)
	local humanoid = object.Parent:FindFirstChild("Humanoid")
	if humanoid ~= nil then
		local player = game.Players:FindFirstChild(humanoid.Parent.Name)
		if player ~= nil then
			local leaderstats = player:FindFirstChild("leaderstats")
			if leaderstats ~= nil then
				local gold = leaderstats:FindFirstChild("gold")
				if gold ~= nil then
					gold.Value = gold.Value + 1
				end
			end
		end
		script.Parent.Coin.Ccoin:Remove()
		workspace.Coin.uni004D:Remove()
	end
end

return FunctionModule

It’s just a function parameter. It is whatever you pass to it.

Because of this line, it seems like object is supposed to be a Part inside of a character, so this function is likely supposed to be connected to a Touched event so that when a player touches the part he gets gold.

so, how would I make it so that It will give him gold?

Pass the function a parameter that is a child of a player’s character, or connect the function to the Touched event of some Part.

I don’t know how to do that…I have tried a lot and i still don’t know

I’m not here to teach people to script. I’m not an educator, there are far better resources out there that do a better job teaching than I could do. Depending of course on what you know already, you’ll need to get to the point where you understand functions and events.

2 Likes

Okay. I’m sorry for wasting your time

As @JarodOfOrbiter said, its a Parameter.

object as no meaning as it is not given one, It is known as any or a which means anything, As in it could be anything.

This is something that you should know.

local function Example(object) -- object is known as "any" or "a"

You can assign its Class by adding a Colon, and typing for inserting the Class, So if i wanted it to be a BasePart i would do this:

local function Example(object: BasePart) -- object is now a Part (any type)

object in your code is the Player’s Character, but its not Assigned as a Model so its considered any by the code.

If you want a Player function, you can do that:

function GiveGold(Player: Player, Item: Instance, Amount: number)
   Player[Item].Value += Amount
end

And then Call it:

GiveGold(Player, Item, 50)
-- Player = Player
-- Item = A Value within the Player
-- Amount = A number

If you don’t know this stuff, or have no Knowledge on how to code Basic things, Its best that you continue to learn the Basics of the Language you are coding in. Check out some Tutorials on YouTube, Tutorials in the Category #resources:community-tutorials or DevHub as these are great resources to learn about Properties, loops, and Functions, or even Code that can be helpful with bigger projects.

Nobody has to teach you how to code because you don’t know how to.

2 Likes

You need to pass an object to the function otherwise it won’t know what object to use.
givegold(script.Parent.Coin)

1 Like