Weird question I know. What I'm trying to achieve is that the script waits until a function has returned something before continuing the code.

The following code gets a player after what p is basicly. This works fine.

function gplr(p)
	local x = false
	local len = string.len(p)
	if len then
		if p == "all" then
			x = true
			print("All")
			return "al"
		elseif p == "me" then
			x = true
			print("Me")
			return "me"
		else
			for i,v in pairs(game:GetService("Players"):GetPlayers()) do
				if string.sub(v.Name:lower(), 1,len) == p then
					x = true
					print("Targ "..v.Name)
					return v
				end
			end
		end
	end
	if not x then
		return nil
	end
end

However, the following code is where i have an issue.

local vic = gplr(string.sub(m,7))
if vic then
	if not vic == "me" then
		unff(vic)
	else
		unff(pl)
	end
end

Basicly, because the return has not happend yet, the code will proceed and select pl instead of the return's command. What I'm hoping for is that it will wait until gplr has returned a value.

3 comments

0

repeat wait() until variable == whatever

0

gshocked that wouldnt work because the variable could be anything. However the issue was just the if not vic == "me" then i changed them to if vic ~= "me" and everything works now.

0

and also i asked the wrong question. the function did indeed return it, but it got mixed up in that line i stated above