I have Script and ModuleScript. This is part of how Script looks:
owner = require(script.Owner)
function process(player)
if owner == nil then
var = require(player.PlayerGui.buyGui.buyFrame.buyScript)(player, price, name, image)
print(var)
end
end
And full ModuleScript:
function wipe()
script.Parent.ProductPrice.Text = '%price%'
script.Parent.houseImage.Image = 'rbxassetid://133293265'
script.Parent.ProductName.Text = '%name%'
script.Parent.Visible = false
end
local buyFunction = function(player, price, name, image)
script.Parent.ProductPrice.Text = price
script.Parent.houseImage.Image = image
script.Parent.ProductName.Text = name
local verify
function verify()
if player.leaderstats.Cash.Value >= price then
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - price
wipe()
return 'success'
elseif player.leaderstats.Cash.Value < price then
wipe()
return 'no_money'
end
end
local close
function close()
wipe()
return 'aborted'
end
script.Parent.BuyButton.MouseButton1Click:connect(verify)
script.Parent.CancelButton.MouseButton1Click:connect(close)
script.Parent.Visible = true
end
return buyFunction
As you can see, ModuleScript returning status of purchase. But var in Script always is nil. It is because Script not waiting for completing actions in ModuleScript. So how to fix that? I think about BindableFunction for that, but interested is there a way to fix it?

4 comments
"the button can be used over and over. ". But wipe function closes window after pressing button so it can't be presed 'over and over'. Interesting idea about function. So you telling me to give to Module function as argument that will be executed after successful purchase? Nice idea, will try if later.
Also, I believe that due to the module returning the "buyFunction" function, the "Wipe" function will not be passed back, so the module will err when it calls it.
No, it won't error. It keeps the environment where it was defined.
@BlueTaslem found a way to fix. I wil return some variable at the end of function, but before wait until user make choice and set this var.