I wanna make a store with a seller where if you click e to a prompt a gui opens and you can buy weapons with points and also with datastore save
The gui can open but when i click the button to buy a item i dont get on the backpack and also the points doesnt subtracts
this is the script of Prompt_Tienda
local MostrarTienda = rs:WaitForChild("MostrarTienda")
print("hi")
prompt.Triggered:Connect(function(jugador)
print("hi")
MostrarTienda:FireClient(jugador, prompt:GetAttribute("item_type"))
print("hello")
end)
this is the script of Compras
print("ComprarItemALPrinicipio si que funciona che")
local rs = game:GetService("ReplicatedStorage")
local ComprarItem = rs:WaitForChild("ComprarItem")
local MostrarTienda = rs:WaitForChild("MostrarTienda")
local NombreMoneda = rs:GetAttribute("moneda")
print("Hi")
function Comprar(jugador, item_id, item_type)
print("comprar funcion anda")
for i, item in pairs(rs.Items:GetChildren()) do
print("El lopp funciona correctamente")
if item:GetAttribute("item_id") == item_id then
local dinero = jugador.leaderstats[NombreMoneda]
local precio = item:GetAttribute("precio")
print(typeof(dinero.Value))
print(typeof(precio))
if dinero.Value >= precio then
dinero.Value = dinero.Value - precio
print("hi againxd")
local it = item:Clone()
item.Parent = jugador.Backpack
print("this should work")
MostrarTienda:FireClient(jugador, item_type)
end
end
end
end
print("hiii")
ComprarItem.OnServerEvent:Connect(Comprar)
this is tienda gui script
local rs = game:GetService("ReplicatedStorage")
local NombreMoneda = rs:GetAttribute("moneda")
print("hola")
local MostrarTienda = rs:WaitForChild("MostrarTienda")
local jugador = game.Players.LocalPlayer
local gui = script.Parent
function Abrir(item_type)
print("tienda_gui funciona")
local saldo = gui.Main.Footer.Saldo
saldo.Text = jugador.leaderstats[NombreMoneda].Value
local items = gui.Main.Items
for i, itemGui in pairs(items:GetChildren()) do
if itemGui:IsA("Frame") then
itemGui:Destroy()
end
end
print("Hi")
for i, item in pairs(rs.Items:GetChildren()) do
if item:GetAttribute("type") == item_type or item_type == "todos" then
local itGui = rs.gui.Item:Clone()
itGui.Imagen.Image = item.TextureId
itGui.Info.Titulo.Text = item.Name
itGui.Info.Precio.Text = item:GetAttribute("precio").." G"
itGui.Parent = items
print("hola")
itGui:SetAttribute("item_id", item:GetAttribute("item_id"))
itGui:SetAttribute("item_type", item_type)
end
end
print("hi again")
gui.Enabled = true
end
MostrarTienda.OnClientEvent:Connect(Abrir)
this is comprar_item script
local boton = script.Parent
local itGui = boton.Parent
local rs = game:GetService("ReplicatedStorage")
local ComprarItem = rs:WaitForChild("ComprarItem")
print("hi1")
boton.MouseButton1Click:Connect(function()
print("comprar_item funciona")
ComprarItem:FireServer(itGui:GetAttribute("item_id"), itGui:GetAttribute("item_type"))
print("2do comprar item")
end)
theres also attributes on the items ( each one has the same attributes else replicatedstorage)
this is replicated storage attributes ( moneda is the name of the coin = points)
this is the item attributes ( precio is price of the item)
there also remote events on ReplicateDStorage
now the locations of the scripts
ALSOOO the prompt ( where you touch the e to open the gui) has a attribute of item_type so it appears which type of items should it sell ( in this case are armas = weapons)
hope someone can help me fix this bug please