Script not reading prints

Hello everyone, I’m folliwing an AlvinBlox tutorial, on making a piggy game. I’m encountering an issue, I’m not getting an error however this happens. when I click buy.

Basically, it’s not printing “bought” or anything other than “You can buy this, proceed” it only prints when they can buy it. It doesn’t allow me to equip it on my version either.

https://gyazo.com/c1f909af5a8c060979f064b2f9b40224

It’s supposed to do this:

https://gyazo.com/f15e313ebef4d77d3db72b9942dd75e5


I have 2 different scripts, that are meant to make this function,

Here is the EventHandling code;

game.ReplicatedStorage.BuyItem.OnServerInvoke = function(player,itemName,itemType)
	local item
	local inInventory
	
	if itemType == "skin" then
		--skin
		item = game.ReplicatedStorage.Skins:FindFirstChild(itemName)
		
		if player.SkinInventory:FindFirstChild("itemName") then
			inInventory = true
		end
		
	elseif itemType == "trap" then
		--trap
		item = game.ReplicatedStorage.Traps:FindFirstChild(itemName)
		
		if player.TrapInventory:FindFirstChild("itemName") then
			inInventory = true
		end
	end	
	
	if item then
		if item:FindFirstChild("Cost") then
			if not inInventory then
				--check if buy
				if item.Cost.Value <= player.Tokens.Value then
					print("You can buy this, proceed")
					player.Tokens.Value = player.Tokens.Value - item.Cost.Value
					
					local stringValue = Instance.new("StringValue")
					stringValue.Name = item.Name
					
					if itemType == "skin" then
						stringValue.Parent = player.SkinInventory
					elseif itemType == "trap" then
						stringValue.Parent = player.TrapInventory
					end
					
					return "bought"
					
				else 
					return "failed"
				end
			else
				--test
				print("You already own this item!")
				if itemType == "skin" then
					player.EquippedSkin.Value = itemName
				elseif itemType == "trap" then
					player.EquippedTrap.Value = itemName
				end
				return "equipped"
		 end
	 end
	else
		print("Not found")
		return "failed"
	end
end

The second script that makes it function is;

function addSkins(data)
	for i, v in pairs(data) do
		local frame = createFrame(v.Name,v.Cost.Value,v,skins.Folder)
		
		frame.Button.MouseButton1Click:Connect(function()
			local result = game.ReplicatedStorage.BuyItem:InvokeServer(v.Name,"skin")
			
			
			if result == "bought" then
				--purchase was a success
				
				frame.Button.Image = greenTick
				frame.Cost.Text = "Owned"
				
			elseif result == "equipped" then
				--you equipped the item
				
				frame.Button.Image = greenTick
				frame.Cost.Text = "Equipped"
				

			end
			
		end)
	end
end

Here is alvinblox’s tutorial video that i’m on

Please help me!

1 Like

You’re not printing ‘bought’ though, you’re just returning the string.

1 Like

Ok but that still doesn’t solve my problem

To my knowledge using return on remote functions do not work, you would have to recall the remote function and pass the params again if you wanted to invoke back to the client

Something like this:

EventHandler

game.ReplicatedStorage.BuyItem.OnServerInvoke = function(player,itemName,itemType)
	local item
	local inInventory
	if itemType == "skin" then
		--skin
		item = game.ReplicatedStorage.Skins:FindFirstChild(itemName)

		if player.SkinInventory:FindFirstChild("itemName") then
			inInventory = true
		end

	elseif itemType == "trap" then
		--trap
		item = game.ReplicatedStorage.Traps:FindFirstChild(itemName)

		if player.TrapInventory:FindFirstChild("itemName") then
			inInventory = true
		end
	end	

	if item then
		if item:FindFirstChild("Cost") then
			if not inInventory then
				--check if buy
				if item.Cost.Value <= player.Tokens.Value then
					print("You can buy this, proceed")
					player.Tokens.Value = player.Tokens.Value - item.Cost.Value

					local stringValue = Instance.new("StringValue")
					stringValue.Name = item.Name

					if itemType == "skin" then
						stringValue.Parent = player.SkinInventory
					elseif itemType == "trap" then
						stringValue.Parent = player.TrapInventory
					end
				
					print("bought")
					game.ReplicatedStorage.BuyItem.InvokeClient("bought")
				else 
					print("failed")
					game.ReplicatedStorage.BuyItem.InvokeClient("failed")
				end
			else
				--test
				print("You already own this item!")
				if itemType == "skin" then
					player.EquippedSkin.Value = itemName
				elseif itemType == "trap" then
					player.EquippedTrap.Value = itemName
				end
				game.ReplicatedStorage.BuyItem.InvokeClient("equipped")
			end
		end
	else
		print("Not found")
		game.ReplicatedStorage.BuyItem.InvokeClient("failed")
	end
end

FUNCTION 

function addSkins(data)
	for i, v in pairs(data) do
		local frame = createFrame(v.Name,v.Cost.Value,v,skins.Folder)
	
		game.ReplicatedStorage.BuyItem.OnClientInvoke = function(result)
			if result == "bought" then
				--purchase was a success

				frame.Button.Image = greenTick
				frame.Cost.Text = "Owned"

			elseif result == "equipped" then
				--you equipped the item

				frame.Button.Image = greenTick
				frame.Cost.Text = "Equipped"


			end
		end
	
		frame.Button.MouseButton1Click:Connect(function()
			game.ReplicatedStorage.BuyItem:InvokeServer(v.Name,"skin")
		end)
	end
end

Edit: I think this might work well for the current situation

In the second script. If result == “bought” then
print (“bought”).

1 Like