Hey Daniel! That sounds like a great plan, and I love your enthusiasm for learning Roblox game design and scripting — especially within ERLC! Let’s start with something simple and clear that gets you comfortable writing your own Lua code.
How about this:
Let's create a simple automatic coin collector in Roblox. This script will make coins collected automatically when the player touches them, so you get hands-on practice with events, functions, and basic scripting.
Step 1: Create a Coin Part in Roblox Studio
- Open Roblox Studio and create a new place or open your ERLC project.
- Insert a Part (this will be the coin). Change its name to
"Coin". Make it a bright color like yellow or gold, and scale it so it looks like a coin.
Step 2: Add a Script to the Coin
- Right-click the Coin in Explorer and insert a Script (not a LocalScript).
- This script will check when a player touches the coin and then award a point or currency.
Step 3: Script to Automatically Collect Coins
Here’s a basic script you can put inside the Coin:
local coin = script.Parent
-- Function called when something touches the coin
local function onTouch(otherPart)
local character = otherPart.Parent
local player = game.Players:GetPlayerFromCharacter(character)
if player then
-- Player touched the coin, add 1 to a leaderstats value called "Cash"
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local cash = leaderstats:FindFirstChild("Cash")
if cash then
cash.Value = cash.Value + 1
end
end
-- Remove the coin from the game (collected)
coin:Destroy()
end
end
-- Connect the Touch event of the coin to the onTouch function
coin.Touched:Connect(onTouch)
Step 4: Create Leaderstats (Cash) for Players
To see the coins add up, players need a "Cash" value. Put this script inside ServerScriptService:
game.Players.PlayerAdded:Connect(function(player)
-- Create leaderstats folder
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
-- Create Cash IntValue
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Value = 0
cash.Parent = leaderstats
end)
How This Helps You Learn:
- Events: Using
.Touched to detect player interaction
- Functions: Breaking your code into small reusable chunks
- Player Data: Accessing player objects and their stats
- Simple logic: Adding values and removing objects
Tips for Breaking it Down:
- Take your time reading and typing each line of code.
- If something is confusing, ask about just that part (like how
.Touched works).
- You can test the feature by playing in Roblox Studio and walking into the coin. The Cash number should increase!
Would you like me to help make the coin respawn automatically so you can collect again and again? Or maybe a different feature next? Just let me know!
You're doing awesome by starting small and building your skills your way. Keep it up, Daniel! 😊