Hi! So basically I’m really struggling with the concept of the backpack/inventory system. I can’t really grasp the concept of it so I completely decided to simplify it entirely and go a different route when approaching it. I have notes that are on the ground scattered throughout my game and I already have it coded to where when you click on it, it opens it up on your screen and you can close out of it when you are done. I have this for all the notes and even for a book I made. The only problem I have is that I want to script it to when someone picks up a note, it stores it in their backpack system so they can go back to read through it later on. Not the typical backpack but one that I have made. In that backpack I’m just going to have text reading “note 1” and then they can click on that button to bring up the note again. How would I go about doing this? Would I have that button open up the same notegui I made or would I have to do something entirely different? I’ll include the scripts I have so far.
This is the physical note that they can click on. This the script inside of it:
This my backpack that I’ve made.
Pretty much going to have blank spots with ??? until they find a note which will pop up with “note 1” or whatever note they found. I’m just not too sure how to go about that to be quite honest. I am very new with scripting so I am trying my best to understand things quickly and take things in but it can sometimes be difficult. Someone did help me with a badge array so maybe I could reuse that but in this sense? Here is the badge array:
local badgeService = game:GetService("BadgeService")
local runService = game:GetService("RunService")
local players = game:GetService("Players")
local player = players.LocalPlayer
local badgesHolder = player.PlayerGui:WaitForChild("shop"):WaitForChild("ShopFrame"):WaitForChild("Background"):WaitForChild("BadgeFrame")
local badges = {
[1] = {
["name"] = "Fruit", -- change to the name of the frame that holds the badge's ui
["displayName"] = "Fruit Ninja", -- change to the name of the badge
["displayDescription"] = "Guess all the Fruit",
['id'] = 2125583474, -- change to badge id
},
local function getUserOwnedBadges()
for _, data in ipairs(badges) do
local badgeId = data.id
local badgeName = data.displayName
local badgeDescription = data.displayDescription
local frameName = data.name
local frameInstance = badgesHolder:FindFirstChild(frameName)
if not frameInstance then warn(string.format("Could not find badge frame with name of %s", frameName)) continue end
local badgeNameInstance = frameInstance:WaitForChild("BadgeName")
local badgeIconInstance = frameInstance:WaitForChild("BadgeIcon")
local badgeDescriptionInstance = frameInstance:WaitForChild("BadgeDescription")
local success, ownsBadge = pcall(function()
return badgeService:UserHasBadgeAsync(player.UserId, badgeId)
end)
if ownsBadge then
badgeIconInstance.ImageColor3 = Color3.fromRGB(255, 255, 255)
badgeNameInstance.Text = badgeName
badgeDescriptionInstance.Text = badgeDescription
else
badgeIconInstance.ImageColor3 = Color3.fromRGB(0, 0, 0)
badgeNameInstance.Text = "???"
badgeDescriptionInstance.Text = "???"
end
end
end
runService.Heartbeat:Connect(getUserOwnedBadges)
Is that the approach I can go by as well? Thank for the help in advance!
Yeah, when I first started scripting, I was stuck on an inventory system too, it can get overwhelming and complicated, just like any new system, but it gets easier with experience.
Could you give me an understanding of where you’re at with scripting?
(It would help me explain it better)
(I lost internet for like 40 minutes so sorry about the late reply!) I’ve only been scripting for less than a month so I don’t have knowledge on a lot of things. I have worked on a table before with a lot of help from people on the devforum. (The badge list I provided is the only experience I have with tables/arrays) I have done remote events as well. I have a remote event set up for my note gui in order for it to open in operation with the note part as well. But really just bits and parts of everything. Setting things up in a script is something I get confused on because I don’t know how to set it up ya know? It’s like I want to do this one thing but am not sure how to do said thing. I guess that can be said for a lot of people starting out tbh.
I know what you mean, I have been there before. To give you a better understanding, it’s more of how you pass information from the Client/Server and how that information is being used on the opposing side.
.
.
.
We can start by setting up the data for the passing/receiving of information. You want to create a variable that holds an empty table at the top of a server script
.
.
.
Next, you would want to get when a player joins, (You can do this by the PlayerAdded Event) then you want to save an empty table to our PlayerData Variable with some reference to our player, in our case it will be the player’s Id.
.
.
.
Since the PlayerAdded Event returns 1 Parameter which is the Player’s Instance that joined, we can use that to get the player’s Id since the UserId is a Property from the Player’s Instance.
.
.
.
Now you want to set up a method for the Client to receive any information being stored in our Player’s Inventory table. In my opinion, the best method is to create a folder instance inside our Player’s instance that contains all the information stored in our inventory.
.
.
.
On the Client-Side, you want to get that same folder instance we just made then watch for anything being added to it with a ChildAdded Event yayyy (Which watches for anything being parented to our Inventory folder)
game.Players.LocalPlayer is just getting the Players Service from Explorer and finding your LocalPlayer(AKA You)
.
.
. phew
.
.
.
You said something about picking up the note and having an option to store it, right? The next part will get a little more interesting, let me know if you got this so far.
Thank you so much for breaking it down this much in depth! This is honestly what I needed because sometimes people put together long scripts and I have no idea what anything from it means. This is starting to make a little more sense to me. It’s two different scripts right? Does it matter if it is local or just a normal one? And as for the scripts, where would it be better to place the scripts?
“Does it matter if it is local or just a normal one?”
Yes, local scripts can interact with the Client via events and vise versa via Server Scripts
“as for the scripts, where would it be better to place the scripts?”
For the Client you have a couple options
StarterCharacterScripts (Scripts ‘reset’ when a player dies)
StarterPlayerScripts (Scripts will continue to run until stopped)
Backpack or PlayerGui (basically the same as #1)
For the server
Anywhere really but make sure to store any important scripts in the ServerScriptStorage because even though players can’t interact with them they can read them which is still pretty bad, you don’t want exploiters understanding how information is being received then manipulating the info being passed through Remote Events
Can also access ServerStorage which is meant for storing any Assets or other things you don’t want exploiters getting a hold of.
Alright! I fixed what I needed to fix. Yes and as for the note, I have an option already where you click on the note and it fires a remote event that open up that note gui. But the player doesn’t physically pick it up. And that is something I want to keep like that. The only thing I want differently is to store said note in their backpack that I made. Would you like to see the setup of my backpack that I have? Rn I only have a script to open the backpack and the whole design of it. Not the script portion.
Alright so here is what my backpack looks like visually
Right here is my backpack
Inside the Item Frame:
So the “BackpackBack” is just the aesthetic frame part of the background. The BackpackFrame holds the Items. And each Item Frame holds the image button (which will show an image of the note.). The TextLabel in each one will hold the name of the note.
I’d probably set it up something like this in terms of tables/arrays. Also in that script, it is set up to where, if they don’t have the badge it shows up as a black image and “???”. That is something similar I would want with the notes as well.
So for the storing of the notes, would it just be easier to call upon the decals I have uploaded of the notes itself instead of calling upon the note gui?
I’m not sure what you mean here but, what you can do is pre-set everything to ‘???’ with a black image and name each ItemFrame the Notes name, then depending on rather or not you have the note we can revert the ItemFrames name and image. andd I have to go somewhere nd wont be back for 2 hours would you want to wait till I get back or I could create a quick way to do it for now
I have a note gui for each note that pops up when someone clicks on it. Each note gui has an image of the note I made somewhere else because the text inside roblox studio can be a bit wonky. And I can try to make something on my own using the badge list array script! But I can also wait as well. I’m in no rush to be honest. Just trying to understand this portion. Thanks for all your help so far!
actually, I’m sorry about that, but you don’t have to have a PlayerData with the inventory stored, since you’re not saving it to DataStores. I’m just so used to doing that.
When a player clicks the notes clicker you could add an attribute to inventory and on the Client’s AttributeChanged detects the attribute added
You can set the attributes key as the notes name and the value as the notes details
Another option is whenever the note gets clicked change a property in it, like even the text to the notes name rather than ???. Then you could have a property changed signal on every note Fran so you can have easier access to all the UI aswell as using that to update the image
The script didn’t work for me I’ll try to explain more in depth about what I have so things make more sense.
So note part:
Contains a click detector with this script:
Now I want to make it where after the note is clicked and the note pops up and whatnot, it is stored in the backpack:
The note will only appear, though, when it is found in the environment. When found the image button will revert to color and reveal the ??? Here’s the script that I found works with it, I just need help with certain things in it.
local runService = game:GetService("RunService")
local players = game:GetService("Players")
local player = players.LocalPlayer
local Backpack = player.PlayerGui:WaitForChild("Backpack"):WaitForChild("BackpackBack"):WaitForChild("BackpackFrame")
local notes = {
[1] = {
["name"] = "Note1", -- change to the name of the frame that holds the badge's ui
["displayDescription"] = "Introduction", -- change to the name of the badge
},
}
local function getUserOwnedBadges()
for _, data in ipairs(notes) do
local badgeDescription = data.displayDescription
local frameName = data.name
local frameInstance = Backpack:FindFirstChild(frameName)
if not frameInstance then warn(string.format("Could not find badge frame with name of %s", frameName)) continue end
local badgeIconInstance = frameInstance:WaitForChild("ButtonImage")
local badgeDescriptionInstance = frameInstance:WaitForChild("TextLabel")
local success, ownsBadge = pcall(function()
return badgeService:UserHasBadgeAsync(player.UserId, badgeId)
end)
if ownsBadge then
badgeIconInstance.ImageColor3 = Color3.fromRGB(255, 255, 255)
badgeDescriptionInstance.Text = badgeDescription
else
badgeIconInstance.ImageColor3 = Color3.fromRGB(0, 0, 0)
badgeDescriptionInstance.Text = "???"
end
end
end
runService.Heartbeat:Connect(getUserOwnedBadges)
The script is set up right now for a badge function but I want to change it so it doesn’t call for that function but I am not sure how. For the “if owns badge” part, is there a way I could script it to where its “if clicked on certain note?” And also as well since it is an image button and whatnot, is it possible for the button to not work until that “if clicked on certain note” is called? I’m sorry if this doesn’t make sense, I am trying to explain as best I can. I do appreciate the help too btw.
Ooohhh I understand lol. I don’t know what my mans did in the OwnedBadges script but he was looping through a for loop checking in the notes table for a new note, endlessly. Here is a better solution.
.
.
.
–Note Clicker Script
local Note = script.Parent
local ClickDetection = Note:WaitForChild('ClickDetection')
ClickDetection.MouseClick:Connect(function(Player) --Player is the first Parameter of MouseClick
local Inventory = Player:FindFirstChild('Inventory') --Gets the (player instance) then gets the first child named inventory
if not Inventory:FindFirstChild(Note.Name) then --(not) is saying if not true
local Folder = Instance.new('Folder')
Folder:SetAttribute('Image', 'IMAGEID')
Folder:SetAttribute('Description', 'ARE YOU OKAY???')
Folder.Parent = Inventory
end
end)
.
.
.
–Client-Side
Make sure to pre-name all the ItemGuis to the notes name
For all the ItemGuis make their TextLabel text “???”
For all the ItemGuis make their ImageColor3 to “0, 0, 0”
local Player = game.Players.LocalPlayer
local Inventory = Player:WaitForChild('Inventory')
--Grab Guis
local PlayerGui = Player:WaitForChild('PlayerGui')
local NotesGui = PlayerGui:WaitForChild('NotesGui')
local NotesFrame = NotesGui:WaitForChild('NotesFrame')
local Backpack = PlayerGui:WaitForChild('Backpack')
local BackpackBack = Backpack:WaitForChild('BackpackBack')
local BackpackFrame = BackpackBack:WaitForChild('BackpackFrame')
Inventory.ChildAdded:Connect(function(Child)
--Get Attribute Values
local Image = Child:GetAttribute('Image')
local Description = Child:GetAttribute('Description')
--Note shows up on the screen
NotesFrame.TextLabel.Text = Description
NotesFrame.ImageLabel = Image
NotesFrame.Visible = true
--Note appears in the backpack
if BackpackFrame:FindFirstChild(Child.Name) then
local Item = BackpackFrame:FindFirstChild(Child.Name)
local ButtonImage = Item:WaitForChild('ButtonImage')
local TextLabel = Item:WaitForChild('TextLabel')
ButtonImage.ImageColor3 = Color3.fromRGB(255, 255, 255)
ButtonImage.Image = Image
TextLabel.Text = Description
end
end)
Yes the buttons are set up but the click detector script for the first script doesn’t work. I think possibly because in my original script I have a remote event in replicated storage that triggers the note gui to become visible. And for the note gui, it just has a note frame that holds an image, and a text button that closes out the note. So the description would only be for the backpack itself.