How To Make A Roblox Game | Learn Roblox Studio
ฝัง
- เผยแพร่เมื่อ 24 ธ.ค. 2024
- Learn Roblox Studio in 2024 with this complete tutorial. Check the pinned comments for the code :)
Two common errors you might run into while running datastores for the first time:
1. You can’t use a datastore unless your game is published. Publish it now, it won’t be shown to others until you choose to
2. “you don’t have API access”if you have this we’re going to fix it by making a Boolean value in ServerStorage. set it to true, and name it SaveinStudio
#robloxgamedevelopment #robloxstudio #roblox
leaderboard code:
local DataStoreService = game:GetService("DataStoreService")
local dataStore = DataStoreService:GetOrderedDataStore("LBStore")
local Players = game:GetService("Players")
local function GetPlayerData(player)
local success, currentValue = pcall(function()
return dataStore:GetAsync(player.UserId) or 0
end)
return currentValue
end
local function UpdatePlayerData(player, value)
local success, err = pcall(function()
dataStore:SetAsync(player.UserId, value)
end)
end
local function IncrementAllPlayers()
for _, player in ipairs(Players:GetPlayers()) do
local currentValue = GetPlayerData(player)
UpdatePlayerData(player, currentValue+1)
end
end
local function UpdateLeaderboard()
local success, errorMsg = pcall(function()
local data = dataStore:GetSortedAsync(false, 10)
local page = data:GetCurrentPage()
for rankinLB, dataStored in pairs(page) do
local name = game.Players:GetNameFromUserIdAsync(tonumber(dataStored.key))
local template = script.Parent.Frame:Clone()
template.TextLabel.Text = "#"..rankinLB.." "..name.." "..tostring(dataStored.value)
template.Parent = script.Parent.TextBox
end
end)
end
--player join handling
Players.PlayerAdded:Connect(function(player)
local currentValue = GetPlayerData(player)
if currentValue == 0 then
UpdatePlayerData(player, 0)
end
end)
spawn(function()
while true do
IncrementAllPlayers()
UpdateLeaderboard()
wait(60)
end
end)
Now it apperars
I originally thought you had 1k+ subs by how high quality this it!
Thank you!! Trying my best to make good vids
Your real good at game development.
Thanks!
Wow great video, new sub!
🤜🤛
Great video! Nicely short, but still with all you need to know to start! Keep creating these🔥
Thanks! Will do!😄
How does this dude only have 250 subs?? Great editing for a new youtuber :)
Ah thank you!! Working hard to improve 😅
thank you very much this really helped me and helped everyone keep going❤❤❤
I'm glad! 🙂
Great video as always 🔥🔥
Thanks for the support :)
@bluebaeryboi no problem!
Cool stuff
yeah u are
@ awww 🥰
Great video!
thanks!
You should make like a longer tutorial in more depth and explaining stuff more. Also you should make a tutorial on how to code!
Good ideas! Yeah a deep dive and a coding one will be nice
underrated
🤜🤛
❤
🙂
where's the part how you promote it 🥺
Coming soon! 😌
function onTouched(obj)
local h = obj.Parent:FindFirstChild("Humanoid")
if h then
h.Health = 0
end
end
game.Workspace.Baseplate.Touched:Connect(onTouched)
Can you do Ike
Local idk = script.Parent
Idk.Touched:Connect(function(touch)
If touch.Parent:FindFirstChild("Humanoid")
Touch.Parent.Humanoid.Health = 0
end)
@@rotchetcomora288 Yes! When you write the script like this, the script must go into the actual part, but as long as it is, it will work the same!
THIS IS THE HARDEST CODE EVER BRO I CANT FIND PINNED COMMENTS UP DOWN NOWARE
local DataStoreService = game:GetService("DataStoreService")
local dataStore = DataStoreService:GetOrderedDataStore("LBStore")
local Players = game:GetService("Players")
local function GetPlayerData(player)
local success, currentValue = pcall(function()
return dataStore:GetAsync(player.UserId) or 0
end)
return currentValue
end
local function UpdatePlayerData(player, value)
local success, err = pcall(function()
dataStore:SetAsync(player.UserId, value)
end)
end
local function IncrementAllPlayers()
for _, player in ipairs(Players:GetPlayers()) do
local currentValue = GetPlayerData(player)
UpdatePlayerData(player, currentValue+1)
end
end
local function UpdateLeaderboard()
local success, errorMsg = pcall(function()
local data = dataStore:GetSortedAsync(false, 10)
local page = data:GetCurrentPage()
for rankinLB, dataStored in pairs(page) do
local name = game.Players:GetNameFromUserIdAsync(tonumber(dataStored.key))
local template = script.Parent.Frame:Clone()
template.TextLabel.Text = "#"..rankinLB.." "..name.." "..tostring(dataStored.value)
template.Parent = script.Parent.TextBox
end
end)
end
--player join handling
Players.PlayerAdded:Connect(function(player)
local currentValue = GetPlayerData(player)
if currentValue == 0 then
UpdatePlayerData(player, 0)
end
end)
spawn(function()
while true do
IncrementAllPlayers()
UpdateLeaderboard()
wait(60)
end
end)
Where
WHERE
The team is the problem here
What's the problem? I don't quite understand :)
Things I'd like to say:
The Command + D thing is on Macbook only I'm pretty sure, if you're on windows then use Ctrl + C, it copies the part/script or object you're working on
Ctrl + V pastes it, so ctrl + c you copy it, ctrl + v you paste it, if you want to paste it into something then select the object you're gonna wanna paste in into, and do Ctrl + Shift + V.
I don't know how to code much but I've started learning from using chat GPT, It gives me scripts and tells me what it does so let's say like:
local script.Parent = sp -- What this means is the parent of the script = sp, let's say you put this script inside a part, script.Parent is the part because it's the script's parent, and sp is something you can use instead of script.parent, so if you put this into a part (script) you can get it to change colours( correct if something is wrong in the script):
this script changes the color of script.Parent and includes setting sp as a shorthand for script.Parent. This script assumes script.Parent is a part that can have its color changed.
Code:
Copy code if you wanna use it
(MAKE SURE YOU PUT THIS INSIDE THE PART OTHERWISE IT WILL NOT WORK!!!, AND MAKE SURE IT'S A SCRIPT NOT A LOCALSCRIPT!!!!)
local sp = script.Parent -- Shortcut for script.Parent
while true do
-- Generate a random color
local randomColor = Color3.new(math.random(), math.random(), math.random())
sp.Color = randomColor -- Apply the random color
wait(1) -- Wait for 1 second
end
you can modify the time, or if you want it to apply certain colours instead then use this script:
local sp = script.Parent -- Shortcut for script.Parent
-- Define a table of colors
local colors = {
Color3.new(1, 0, 0), -- Red
Color3.new(0, 1, 0), -- Green
Color3.new(0, 0, 1) -- Blue
}
while true do
-- Pick a random color from the table
local randomColor = colors[math.random(1, #colors)]
sp.Color = randomColor -- Apply the random color
wait(1) -- Wait for 1 second
end
I can also give you more help in the replies, I will start making studio videos soon on how to make for example a shop, leaderstats and datastore system, leaderstats is for example a stat in the leaderboard, which counts for coins/kills and data store stores data, if you need any help pleeease reply to me I'm open to giving help
edit: you will succed in making popular games if you keep on trying, get weapons/tools/scripts from the toolbox and look at how they're structured and made, from that you can learn how to make things, if you need assistance please ask me or chatgpt if you need to find models from the toolbox or tutorials
WHERE