RemoteFunction keeps returning nil when it is impossible to return nil

This is my script.

-- LocalScript
local event = game.ReplicatedStorage.Purchase:InvokeServer(ButtonClone.Name)
print(event) -- Line 48
-- ServerScript
local ModuleScript = require(game.ReplicatedStorage.Shop)

game.ReplicatedStorage.Purchase.OnServerInvoke = function(plr,name)
	function buy(item,ItemID)
		local Price = ModuleScript.prices[item]
		local bought = string.split(plr.Bought.Value..",")
		local hasBought = table.find(bought,tostring(ItemID))
		if plr.leaderstats.Coins.Value >= Price and hasBought == nil then
			print("it should be true")
			plr.leaderstats.Coins.Value -= Price
			plr.Bought.Value = plr.Bought.Value..ItemID..","
			return true
		elseif hasBought == 1 then
			print("it should be false") -- Line 17
			return false
		elseif hasBought ~= nil and hasBought ~= 1 then
			print("it should be .")
			return "."
--"BoolValue",plr).Name = "Banned"
--			plr:Kick("You have been banned.")
			print("it should be idk whats goin on")
			return "idk whats goin on"
	local function gamepassBuy()
	if ModuleScript.effectsShop[name] then
	elseif ModuleScript.ranksShop[name] then
	elseif ModuleScript.passesShop[name] then
	elseif ModuleScript.gearsShop[name] then

So basically, if the player doesn’t have the item and has enough money, it will return true, but if the player has the item already, it returns false. If it’s neither of these situations are what’s happening, then it will return “idk whats goin on”.

Yet the output is:

it should be false - Server - ShopScript:17
nil - Client - LocalScript:48

How is the RemoteFunction returning nil when there is 0 way for it to be doing that?? Everything works properly, like the ModuleScript.functions part, so its just the return part that’s wrong.

If none of these four if statements execute, your script won’t launch any functions and thus return nil. I’m not familiar with your game and how it works, so you should either add a return statement at the very end of the invoke connection to return something if nothing else returns. Or analyze why the if statements aren’t being executed.

You’re not returning the result on the function calls

They do execute. The output prints “it should be false” which is just 1 line away from the return statement, and in the same function.

Can you elaborate? I don’t understand what you mean

You’re only calling the functions, you’re not returning what they returned

return buy(...)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.