Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Pcall is broken and not reading my function?

I made multiple pcalls before and they work, but nowdays they dont work. Here is one of my scripts I was making with someone else.

local s, m = pcall(FindPlayer())
	if s then
		--stuff
	else
		warn('Attempted to add "'..plr:GetFullName()..'" to the list!')
	end

The function:

function FindPlayer()
	game.Players:GetPlayerFromCharacter(plr)
end

The error says

ServerScriptService.MainScript:68: bad argument #1 to 'pcall' (function expected, got no value)

even though it is a function.

1 answer

✓ Accepted answer

You don't call the function in pcall, you just give it the function you want to run. In other words, do this for your first line: local s, m = pcall(FindPlayer)

The reason it gave the error it did is because you called FindPlayer(), which returned nothing, and then pcall attempted to run the "nothing" you gave it.

2 comments

0

Also put all of your code into the function. pcall also returns whether the code threw an error, not whether whatever you wanted it to do happened.

0

Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.