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!