Remote Function returning nil instead of "Owned"

So when I buy an item it should return a value “Owned” but instead it returns nil
Module Script

BuyHandler.BuyItem = function(Player, ItemName, Type, Action)
	local Profile = DataHandler:GetProfile(Player)
	
	
	if Player and ItemName and Type then
		if Type == "Backpack" then
			if Action == "Buy" then
				local ItemCost = Items.Storages[ItemName].Cost
				
				if ItemCost ~= nil or Profile.Data.Leaderstats.Coins ~= nil then
					if Profile.Data.Leaderstats.Coins >= ItemCost then
						DataHandler:SetValue(Player, "Leaderstats", "Coins", Profile.Data.Leaderstats.Coins - ItemCost)

						DataHandler:SetBackpackValue(Player, "Backpacks", ItemName)

						DataHandler:SetValue(Player, "Stats", "CurrentBackpack", ItemName)

						DataHandler:SetValue(Player, "Stats", "Backpack", Items.Storages[Profile.Data.Stats.CurrentBackpack].Capacity)
						return "Owned"
					else
						return {"Not Enough Coins", "Coins", Items.Storages[ItemName].Cost}
					end
				end
				
			elseif Action == "Equip" then
				
			elseif Action == "BuyAll" then
				
			
			end
		elseif Type == "Flavors" then
			
		
		end
	end
end
local Message = RemoteFunctions.BuyItem:InvokeServer(GumStorageName.Text, "Backpack", Action)
print(Message) -- prints "nil"
if Message == "Owned" or Message == "Equipped" then
print(Message)
end
1 Like

print(Action) before you Invoke, it could be Action is nil

1 Like

it does print the action “BUY”

1 Like

I see the error, you said it prints BUY which means that:

is false because
Action == "BUY"
Fix the capitalization. Script:

BuyHandler.BuyItem = function(Player, ItemName, Type, Action)
	local Profile = DataHandler:GetProfile(Player)
	
	
	if Player and ItemName and Type then
		if Type == "Backpack" then
			if Action == "BUY" then
				local ItemCost = Items.Storages[ItemName].Cost
				
				if ItemCost ~= nil or Profile.Data.Leaderstats.Coins ~= nil then
					if Profile.Data.Leaderstats.Coins >= ItemCost then
						DataHandler:SetValue(Player, "Leaderstats", "Coins", Profile.Data.Leaderstats.Coins - ItemCost)

						DataHandler:SetBackpackValue(Player, "Backpacks", ItemName)

						DataHandler:SetValue(Player, "Stats", "CurrentBackpack", ItemName)

						DataHandler:SetValue(Player, "Stats", "Backpack", Items.Storages[Profile.Data.Stats.CurrentBackpack].Capacity)
						return "Owned"
					else
						return {"Not Enough Coins", "Coins", Items.Storages[ItemName].Cost}
					end
				end
				
			elseif Action == "Equip" then
				
			elseif Action == "BuyAll" then
				
			
			end
		elseif Type == "Flavors" then
			
		
		end
	end
end
1 Like

I already fix it I just have to return the module script

1 Like

Ok, well either way that should be an issue.

1 Like

You should mark their reply as the solution since they’re technically correct "BUY" == "Buy" will always evuluate to ‘false’.

1 Like