on this note use the wiki with ai, so if you dont know something you read the wiki, then ask the ai about specific things, ai as a whole isnt very good for coding but it is good when it comes to asking specific questions for example ‘Whats the difference between a remote event and a bindable event’ itl be able to tell you that kind of thing.
I highly reccomend making small sections of code relating to specific topics then building on that as you go along, itl go something like this:
variables + accessing parts via game.Workspace.Part
in built functions - take ^ and use :FindFirstChild(“Part”) and try it with different names parts and printing
basic if statements - if Part then do x, pretty standard code
basic functions - When function called find the part
basic event - find a part, when the part is touched run x code
parenting - how about finding the player from the part thats returned from the touched event
basic tables - now lets make a folder containing a whole load of parts, once the part is touched use a for loop to change all of the parts colours
combining loops and basic events - now lets say we want each part to change when only itself is touched, a for loop that connects the touched event to each part
so far what this covers is more or less
local Part = game.Workspace.Part
if Part then
Part.BrickColor = "Green"
end
--Upgrade
local Part = game.workspace:FindFirstChild("Part")
Part.Touched:Connect(function(TouchedPart)
Part.BrickColor = "Green"
end)
--- Upgrade
local Part = game.workspace:FindFirstChild("Part")
Part.Touched:Connect(function(TouchedPart)
for i,v in pairs(game.workspace.PartsFolder:GetChildren() do
v.BrickColor = "Green"
end
end)
--- Upgrade
local Parts = game.workspace.PartsFolder:GetChildren() -- Gets the list of parts
for i,,v in pairs(Parts) do --I being the index, eg 1,2,3 and v being the value, eg part
v.Touched:Connect(function(Part) --This is how we define a function and connect it
v.BrickColor= "Green" --Just a example color
end) -- This is the end of :Connect
end
then thatd be the basics of like parts etc until later on when you have a more specific use case.
then we would move to say data store which learning those kind of goes like:
Getting the service - Common and rather easy its a inbuilt function which we touched on before
Getting the store - the name of the store you want to access
Saving, loading and updating the store using a player id - Ayncs
next up we have error handling, as datastores can fail and if you dont catch errors thats bad news
so that will use pcall, maybe include a loop that breaks when it succeeds at saving/loading
-- Very bare bones basics
local DSS = game:GetService("DataStoreService") -- Short For DataStoreService
local Store = DSS:GetDataStore("NameOfTheStore") -- Get The Name of the store
local Data = Store:GetAsync(UserID) or 0 --Or can be used, so if theres no data its 0
-- improving this
local function SetData(Store,Key)
local Store = DSS:GetDataStore("NameOfTheStore") -- Get The Name of the store
Store:SetAsync(UserID)
end
-- Upgrading again
local function SetData(Store,Key)
local Store = DSS:GetDataStore("NameOfTheStore") -- Get The Name of the store
local S,E = pcall(function() -- Catches error, S for success, E for error
Store:SetAsync(UserID) -- Code we want to catch errors for
end)
if S then --It saved
return --Could also use break, but return exits out of the function as well
-- We want to do this otherwise our code will run multiple times
-- Keeps code running faster, as well as datastores having limits
-- This is pretty standard procedure with datastores
end
end
-- Upgrading again
local function SetData(Store,Key)
local Store = DSS:GetDataStore("NameOfTheStore") -- Get The Name of the store
for i=1,5 do -- Runs this code 5 times (Unless break or return is used)
local S,E = pcall(function() -- Catches error, S for success, E for error
Store:SetAsync(UserID) -- Code we want to catch errors for
end)
if S then --It saved
return --Could also use break, but return exits out of the function as well
-- We want to do this otherwise our code will run multiple times
-- Keeps code running faster, as well as datastores having limits
-- This is pretty standard procedure with datastores
end
end
end
-- Using this function (Assume we made these for loading etc too
local PlayerData = {} -- Lets make a dictionary to store the player data (Table of sorts)
game.Players.PlayerAdded:Connect(function(Player) -- Someone joined lets get data
-- so PlayerData["PLAYER1"] will hold this players data
-- Note on this next line i use to string, this is beacause datastores use string
PlayerData[Player.Name] = LoadData("Inventory",tostring(Player.UserID)) or {}
-- so this here will either load their inventory, or create a new table
end)
--now lets say they buy or pick up a item, lets add that
table.insert(PlayerData["Player1"],"Grapple Hook")
--then we save it when they leave
game.Players.PlayerRemoving:Connect(function(Player) -- Event And Connected function
SaveData("Inventory",tostring(Player.UserID)) -- Our function to save
end)
This is by no means a perfect example but its a good example of how things quickly layer up with each set of improvements, for every what if you have, like what if this was easier to use, theres a soloution, This code here could still be improved by miles but this is kind of the proccess most of us actually go through when learning to do real code.
Youtube tutorials will hold you back from this self review/improvement method that actually gets you to learn things and come up with methods that work with your own scripting style
Main thing to learn early doors is the general layout of code, eg function contains this, if we use :Connect(Fuc) we can create the function within :Connect(), using for i,v in pairs, the difference between findfirstchild and waitforchild and when to use them.
What id do is give this a crack, so follow along what ive said with each itteration of improvements, see what changed and why, what benifits is there to doing that method vs what we had before even though both work
Your learn pretty early on that its worthwhile having functions as you can essentially copy and paste to do what you want, What id advise is follow along with this and then look at small scale coding exersizes, like from what we made above thats literally only a couple of steps away from being able to function as a game where you run around picking up items
Some things to read up on/ask your ai:
Dictionarys + tables whats the difference
What can I put into said tables + dictionarys (DataTypes)
common roblox events eg PlayerAdded/Removed and why its good to use events instead of loops
Client vs Server scripts, what can server do that client cannot, and vise versa
Client vs Server replication, as in what happens on the client only happens for 1 player, server is all
What is a module script and when might you use one
How does this effect the code you write, eg a handler for something, or just a means to functions
Whats the difference if both a server and client use the same module script
can you detect if its the server or client thats calling on the modules functions
theres more advanced topics that lead on from this but this is the baseline of more or less what you need for entry level coding and this is arguably the most important bits to learn, the context you learn at the start now will effect how you learn everything that follows so if you get real familiar with the basics your have a easier time later on