How would I print a value from a function

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Get the multiplier value.

  2. What is the issue?

  3. What solutions have you tried so far? I’ve looked around, I’ve checked the Developer Hub. I know what the problem is. I just don’t know how to fix it. I want to get the returned value (MULTI) but it’s trying to give me the for i, v in pairs information also.

How would I get just the returned Multi value?

local function getMultiplier(Player, Multipler1)
	local Multi = 0
	for i,v in pairs(Player.Pets:GetChildren()) do
		if v.Equipped.Value == true then
			Multi = Multi + v[Multipler1].Value
	return Multi

local multi = getMultiplier()
1 Like

What do you receive in the output?

1 Like
  21:09:04.738  ServerScriptService.Script:7: attempt to index nil with 'Pets'  -  Server - Script:7
  21:09:04.738  Stack Begin  -  Studio
  21:09:04.738  Script 'ServerScriptService.Script', Line 7 - function getMultiplier  -  Studio - Script:7
  21:09:04.739  Script 'ServerScriptService.Script', Line 15  -  Studio - Script:15
  21:09:04.739  Stack End  -  Studio
1 Like

‘Player’ is nil. When you run the function getMultiplier() you must input the player as the first parementer

1 Like

getMultiplier() requires 2 values to be passed to it when called otherwise the script will just throw an error.

1 Like
  21:17:47.339  ServerScriptService.Script:9: invalid argument #2 (string expected, got nil)  -  Server - Script:9
  21:17:47.339  Stack Begin  -  Studio
  21:17:47.339  Script 'ServerScriptService.Script', Line 9 - function getMultiplier  -  Studio - Script:9
  21:17:47.339  Script 'ServerScriptService.Script', Line 16  -  Studio - Script:16
  21:17:47.339  Stack End  -  Studio

Now it’s shooting this error.

You need to call the function and pass 2 values to it.

1 Like

Ah I see, doing that right now.

Okay, so I understand how to pass values, I just don’t know what values I would be passing here for some reason.

Scratch that, my brain is just fried right now. I think I’ve got it.