Jobless_Baby: Need Help with Lua Scripting

NEW❗

Hey fellow coders, I'm eager to learn Lua scripting for my game development project, and I could use some guidance. Can someone experienced in Lua help me with printing a message to the console? Your assistance would be greatly appreciated!

          
function printHello()
  console.log("Hello, World!")
end
printHello()
          
        
πŸ’¬ Chungus Master

COMMENT: Hi there! I noticed a small mistake in your code. In Lua, you use 'print()' instead of 'console.log()'. I have corrected your code as seen below! Lua is different from JavaScript in this aspect. To get started with Lua, you might want to explore the tutorials on the Roblox Documentation: Roblox Documentation. It's a great resource for Lua learners. Good luck with your project!

was this helpful?

          
function printHello()
  print("Hello, World!")
end
printHello()
          
        

10 Minutes Ago



Gnome: Survival Timer

NEW❗

I'm trying to make a game that shows you how long you have survived and I've made a lobby and I'm trying to make a script that starts ticking up by 1 when you touch the teleporter that gets you out of the lobby. It works but it only gives it to one person and randomly ticks up. How do I fix it?





          
game.Players.PlayerAdded:Connect(function(plr)
     leaderstats = Instance.new("Folder", plr)
    leaderstats.Name = "leaderstats"
    
     money = Instance.new("IntValue", leaderstats)
    money.Name = "TimeSurvived"
end)
script.Parent.Touched:Connect(function(hit)
    local part = script.Parent
    if hit then
        while true do
            money.Value = money.Value +1
            wait(1)
        end
    end
end)
          
        
πŸ’¬ DevVince
COMMENT:
  1. Global variable causing a shared timer amongst players.
  2. Missing player-specific data in leaderstats.
  3. No check for touching player, leading to potential errors.
The corrected code for #3 is below this
          
     script.Parent.Touched:Connect(function(hit)
                local part = script.Parent
                local character = hit.Parent
                local player = game.Players:GetPlayerFromCharacter(character) -- this checks if (hit) is actually a players model
                
                if player then -- if the hit is a player then it runs code 
                    while true do --inf loop
                        local leaderstats = player:FindFirstChild("leaderstats") --finds the parent players leaderstats folder
                        if leaderstats then -- if leaderstats exists then it runs the code below
                            local money = leaderstats:FindFirstChild("TimeSurvived") -- finds if "TimedSurvived"'s IntValue in the leaderstats folder if not then it will not run
                            if money then
                                money.Value = money.Value + 1
                            end
                        end
                        wait(1)
                    end
                end
            end)
          
        

was this helpful?

14 Minutes Ago