How can I select data from profile Service?

Well, I will try to explain as easy and brief as possible. Well, I’m making a refrigerator which takes data from the profileService in order to get visible information from the player, so if there is only water in your ProfileService inventory, an ImageButton will be duplicated which will serve to show how much water you have. My problem is that I want to select some data (since there will be several such as water, bread, meat, etc.) but I don’t know how to choose them so that when you press a button after having chosen some data, it can be removed from there (I just want that you can choose, I’ll do it to get the data). All this is done from a server script.

local Players = game:GetService("Players")
local TweenService=game:GetService("TweenService")
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")

local InventoryRemote = ReplicatedStorage:WaitForChild("InventoryFunctions")

local DataManager = require(game.ServerScriptService:WaitForChild("DataStore"):WaitForChild("Configurations"):WaitForChild("DataManager"))

local Proximity = script.Parent:WaitForChild("DoorRefrigerator"):WaitForChild("ProximityPrompt")

Proximity.Triggered:Connect(function(player)
	local Profile = DataManager:Get(player, true)
	Proximity.Enabled = false
	
	local Player_Gui = player.PlayerGui
	local Backpack = player.Backpack
	
	local Menu_de_mapa = Player_Gui:WaitForChild("MenuDeMapa")
	local Objects = Menu_de_mapa:WaitForChild("Objects")
	local Sample = Objects:WaitForChild("Sample")

	for _, GetObjects in pairs(Profile.Data.Other_objects_and_tools.Food_from_refrigerator) do
		if GetObjects.Stacks > 0 then
			local ObjectButton = Sample:Clone()
			ObjectButton.Visible = true
			ObjectButton:WaitForChild("ImageLabel"):WaitForChild("Stack").Text = GetObjects.Stacks
			ObjectButton:WaitForChild("Name_item").Value = GetObjects.Name
			ObjectButton:WaitForChild("Stack_item").Value = GetObjects.Stacks
			ObjectButton.Parent = Objects:WaitForChild("Get_items")
			
			ObjectButton.MouseButton1Click:Connect(function()
				Objects.Frame.ItemName.Text = GetObjects.Name
				TweenService:Create(Objects.Frame.Equip, TweenInfo.new(0.3), {BackgroundColor3 = Color3.fromRGB(118, 118, 118)}):Play()
			end)
			Objects.Frame.Equip.MouseButton1Click:Connect(function()
				print(GetObjects.Name)--here I try to get the object, but it gives me all the objects because there are none selected.
			end)
		end
	end
	Objects.Titulo.TextButton.MouseButton1Click:Connect(function()
		Objects.Visible = false
		Proximity.Enabled = true
		Menu_de_mapa.Action_enabled_map.Value = false
		TweenService:Create(Objects.Frame.Equip, TweenInfo.new(0.3), {BackgroundColor3 = Color3.fromRGB(66, 66, 66)}):Play()
		InventoryRemote:FireClient(player, true)
		for _, Buttons in pairs(Objects:WaitForChild("Get_items"):GetChildren()) do
			if Buttons:IsA("ImageButton") then
				Buttons:Destroy()
			end
		end
	end)
	InventoryRemote:FireClient(player, false)
	Menu_de_mapa.Action_enabled_map.Value = true
	Objects.Visible = true
end)
1 Like

Can you confirm that when running in studio the buttons are being created on the server and visible on the player?

That’s right, the buttons are created from the server

Perhaps instead of using GetObjects.Name you print the Objects.Frame.ItemName.Text

What I mean is that I want to select the objects by just clicking their ImageButton, in fact apparently they are selected, but when pressing the other button that I want to get the data out of there, it gives me all the data

Maybe a solution is:

local SelectObject = nil
ObjectButton.MouseButton1Click:Connect(function()
	Objects.Frame.ItemName.Text = GetObjects.Name
	TweenService:Create(Objects.Frame.Equip, TweenInfo.new(0.3), {BackgroundColor3 = Color3.fromRGB(118, 118, 118)}):Play()
	SelectObject = GetObjects
end)
Objects.Frame.Equip.MouseButton1Click:Connect(function()selected.
	print(SelectObject.Name)
end)

What!?? This makes absolutely no sense (I can’t understand it)

Can you clearly explain what you are trying to do and what the problem is?

Sorry, I’m trying to be able to pick items from inventory this way:

But I don’t know how to grab them, so to speak, so that with another button I can do a function with the chosen object.
Sorry, I have a hard time explaining

evidently


Listen I don’t know what you are talking about, what does “pick them” and “grab them” mean?

All I can do is explain to you how ProfileService works.

Once you have a Profile (I assume you know how to get that), it’s just a normal lua table. You treat it like a normal lua table.

ProfileService allows you to store things in the “Data” field.

So you can easily see values stored in Profiles by doing

Profile.Data.Value.Value.Value -- you can have as many subtables as you want

I’m sorry you are being very unclear on what you want and what the problem is, that’s all I can help you unless I get more information

1 Like

I found the solution

local Players = game:GetService("Players")
local TweenService=game:GetService("TweenService")
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")

local InventoryRemote = ReplicatedStorage:WaitForChild("InventoryFunctions")

local DataManager = require(game.ServerScriptService:WaitForChild("DataStore"):WaitForChild("Configurations"):WaitForChild("DataManager"))

local Proximity = script.Parent:WaitForChild("DoorRefrigerator"):WaitForChild("ProximityPrompt")

Proximity.Triggered:Connect(function(player)
	local Profile = DataManager:Get(player, true)
	Proximity.Enabled = false
	
	local Player_Gui = player.PlayerGui
	local Backpack = player.Backpack
	
	local Menu_de_mapa = Player_Gui:WaitForChild("MenuDeMapa")
	local Objects = Menu_de_mapa:WaitForChild("Objects")
	local Sample = Objects:WaitForChild("Sample")
	
	local SelectedObject = nil--Well, here I change the nil for the chosen data

	for _, GetObjects in pairs(Profile.Data.Other_objects_and_tools.Food_from_refrigerator) do
		if GetObjects.Stacks > 0 then
			local ObjectButton = Sample:Clone()
			ObjectButton.Visible = true
			ObjectButton:WaitForChild("ImageLabel"):WaitForChild("Stack").Text = GetObjects.Stacks
			ObjectButton:WaitForChild("Name_item").Value = GetObjects.Name
			ObjectButton:WaitForChild("Stack_item").Value = GetObjects.Stacks
			ObjectButton.Parent = Objects:WaitForChild("Get_items")
			
			ObjectButton.MouseButton1Click:Connect(function()
				SelectedObject = GetObjects--Here you select
				Objects.Frame.ItemName.Text = GetObjects.Name
				TweenService:Create(Objects.Frame.Equip, TweenInfo.new(0.3), {BackgroundColor3 = Color3.fromRGB(118, 118, 118)}):Play()
			end)
		end
	end
	Objects.Frame.Equip.MouseButton1Click:Connect(function()
		print(SelectedObject.Name)--Here then I will make you can do whatever you want with the chosen data
	end)
	Objects.Titulo.TextButton.MouseButton1Click:Connect(function()
		Objects.Visible = false
		Proximity.Enabled = true
		Menu_de_mapa.Action_enabled_map.Value = false
		TweenService:Create(Objects.Frame.Equip, TweenInfo.new(0.3), {BackgroundColor3 = Color3.fromRGB(66, 66, 66)}):Play()
		InventoryRemote:FireClient(player, true)
		for _, Buttons in pairs(Objects:WaitForChild("Get_items"):GetChildren()) do
			if Buttons:IsA("ImageButton") then
				Buttons:Destroy()
			end
		end
	end)
	InventoryRemote:FireClient(player, false)
	Menu_de_mapa.Action_enabled_map.Value = true
	Objects.Visible = true
end)
1 Like