Help with functions

So I have 2 functions which I will connect both when a remote event is fired from the client.

I want

return verifySuccess

to be used in processRequest()

Basically the player makes a request to own a tycoon, the verify function checks to see if they are already owning a tycoon and if they dont returns verifySuccess true,

look at this code here:

local success = nil
local verifySuccess = nil

-- verify 

local function verify(player)
	if PlayerValues:FindFirstChild(player.Name).IsOwningTycoon == false then
		verifySuccess = true
		return verifySuccess
	else
		
	end
end

local function processRequest()
	
end

ClaimRequest.OnServerEvent:Connect()

How do I make processRequest() know that verifySuccess is true?

I’m pretty sure you need to use remote functions for this.

( Client > Server > Client )

I know that, but my question is how do I let another function know that a value is true

You can call the verify function within the processRequest function.

I just realized that utilizing a remote function might be better, because this will make my code messy

1 Like

This is quite simple actually. In your verify function, the last line stated, return verifySuccess. So when you call that function, if you put it in a variable, the value that is returned gets stored in that variable. Here’s an example code:

local function hi(something)
  if something == true then
     return "ItsTrue"
end

-- Now I will declare a variable to call the function
local var = hi(true)
print(var)

-- It should print, ItsTrue when run.
1 Like

Maybe you could try a remote function.

Client:

local myRemoteFunction = game:GetService('ReplicatedStorage').RemoteFunction

local isSuccessful = myRemoteFunction:InvokeServer()

assert(isSuccessful, 'Oh no! I already own a tycoon!')

Server:

local myRemoteFunction = game:GetService('ReplicatedStorage').RemoteFunction

local function verify(player) -- check if they own a tycoon
    return PlayerValues:FindFirstChild(player.Name).IsOwningTycoon == false
end

myRemoteFunction.OnServerInvoke = function(player)
    local playerCanGetTycoon = verify(player)
    if playerCanGetTycoon then
        -- not sure how you're going about claiming tycoons but that would probably be done here
    end
    return playerCanGetTycoon
end

You didn’t have to write all that :smiley: thanks!

1 Like