Lua - Reddit – Telegram
Lua - Reddit
31 subscribers
281 photos
31 videos
4.27K links
News and discussion for the Lua programming language.

Subreddit: https://www.reddit.com/r/lua

Powered by : @r_channels & @reddit2telegram
Download Telegram
need noscripts combined please.

Hello everyone,

I got an .lua based NowPlaying widget for my linux mint system, run by the app Conky. It looks like this in action:

https://i.imgur.com/0uRWo0Z.png

The author has retired from the forums so I can't turn to him for help. What you see is the result of 2 .lua files building the total displays. One has code to only display if audacious is running, the other only if audacious is playing. The newest edits were created by ChatGPT3.5 and probably look ridiculous to a live coder. It did get the time remaining, numeric volume percentage, and volume bar coded and working, but cannot combine any of these features with the main .lua without breaking it so that nothing at all displays.

I would like to slowly try to merge these two .lua noscripts, and would like to start with the routine to display the time remaining on currently playing track that counts down each passing second. That is in this .lua:

require 'cairo'

-- Function to check if Audacious is playing
function isaudaciousplaying()
local status = execcommand("playerctl -p audacious status")
return status:match("Playing")
end

-- Main function for Conky
function conky
main()
if conkywindow == nil or not isaudaciousplaying() then
return
end

local surface = cairo
xlibsurfacecreate(conkywindow.display, conkywindow.drawable, conkywindow.visual, conkywindow.width, conkywindow.height)
local cr = cairo
create(surface)

-- Draw volume bar and remaining time
drawvolumebar(cr)
drawremainingtime(cr)


cairodestroy(cr)
cairo
surfacedestroy(surface)
collectgarbage()
end

-- Function to execute shell command and get output
function exec
command(command)
local handle = io.popen(command)
local result = handle:read("a")
handle:close()
return result
end

-- Function to get the current volume
function get_volume()
local command = "pactl get-sink-volume
@DEFAULT_SINK@ | awk '{print $5}'"
local output = exec_command(command)
return tonumber(output:gsub("%%", "") or "0")
end

-- Function to convert RGB color to RGBA
function rgb_to_rgba(color, alpha)
return ((color / 0x10000) % 0x100) / 255., ((color / 0x100) % 0x100) / 255., (color % 0x100) / 255., alpha
end

-- Draw the volume bar and numeric volume display
function draw_volume_bar(cr)
local volume = get_volume()
local pct = volume / 100
local bar_properties = {
x = 164, -- X position of the bar
y = conky_window.height - 42, -- Y position of the bar
width = conky_window.width - 232, -- Width of the bar
height = 6 -- Height of the bar
}

-- Draw the background of the volume bar
cairo_set_source_rgba(cr, rgb_to_rgba(0xffffff, 0.3)) -- White color with 0.3 alpha
cairo_rectangle(cr, bar_properties.x, bar_properties.y, bar_properties.width, bar_properties.height)
cairo_fill(cr)

-- Draw the filled portion of the volume bar
local filled_width = pct
barproperties.width
cairo
setsourcergba(cr, rgbtorgba(0xFFFFFF, 1)) -- White color
cairorectangle(cr, barproperties.x, barproperties.y, filledwidth, barproperties.height)
cairo
fill(cr)

-- Draw the numeric volume value
local volumetext = tostring(volume) .. "%"
local x = bar
properties.x + barproperties.width - 102 -- Adjust the x position for the text
local y = bar
properties.y + barproperties.height / 2 - 8 -- Adjust the y position for the text

cairo
setsourcergba(cr, 1, 1, 1, 1) -- White color for the text
cairoselectfontface(cr, "Neon 80s", CAIROFONTSLANTNORMAL, CAIROFONTWEIGHTNORMAL)
cairo
setfontsize(cr, 12)
cairomoveto(cr, x, y)
cairoshowtext(cr, volumetext)
cairo
stroke(cr)
end

-- Function to get the current position of the track
function getcurrentposition()
local command = "playerctl position"
local output = execcommand(command)
return tonumber(output) or 0
end

-- Function to get the total duration of the track
function get
totalduration()
local command = "playerctl metadata mpris:length"
local output = exec
command(command)
return tonumber(output) / 1000000 or 0 -- Convert from microseconds to seconds
end

-- Function to convert seconds to HH:MM:SS or MM:SS format
function secondstotime(seconds)
local hours = math.floor(seconds / 3600)
local minutes = math.floor((seconds % 3600) / 60)
local secs = math.floor(seconds % 60)

if hours > 0 then
-- Format as HH:MM:SS if there are hours
return string.format("%d:%02d:%02d", hours, minutes, secs)
else
-- Format as MM:SS if there are no hours
return string.format("%02d:%02d", minutes, secs)
end
end

-- Function to draw the remaining track time as a numerical value
function drawremainingtime(cr)
local currentposition = getcurrentposition()
local total
duration = gettotalduration()

-- Calculate remaining time
local remainingtime = totalduration - currentposition

-- Convert remaining time to appropriate format
local remaining
text = secondstotime(remainingtime)

-- Add "-" sign before the time
remaining
text = "-" .. remainingtext

-- Adjust position
local x = 20 + (conky
window.width - 40) / 2 -- Center the text horizontally
local y = conkywindow.height - 50 - 4 -- Position 14 pixels above the volume bar

-- Modify these values to move the text
x = x + 32 -- Adjust horizontal position
y = y - 16 -- Adjust vertical position (subtract to move up)

-- Draw the white text on top
cairo
setsourcergba(cr, 1, 1, 1, 1) -- White color
cairoselectfontface(cr, "Neon 80s", CAIROFONTSLANTNORMAL, CAIROFONTWEIGHTNORMAL)
cairo
setfontsize(cr, 12)
cairomoveto(cr, x, y) -- Original position for white text
cairoshowtext(cr, remainingtext)
cairo
stroke(cr)

-- Draw the black stroke text second
cairosetsourcergba(cr, rgbtorgba(0x000000, 1)) -- Black color
cairo
moveto(cr, x + 1, y + 1) -- Offset the black text slightly
cairo
showtext(cr)
cairo
stroke(cr)
end


I would like the time remaining display removed from the above and added to this .lua please:

require 'cairo'
require "imlib2"
homepath = os.getenv ('HOME')
-- Hier den genutzen Pfad zum Conky Verzeichnis eintragen / Enter the used path to the Conky directory here
conky
path = homepath..'/.conky/NowPlayingConky/'
-- Ende Pfad zum Conky Verzeichnis / End Path
image
path = '/tmp/'
pt={}
pt'bg_color'=0xffffff
pt'bg_alpha'=0.3
pt'fg_color'=0xffffff
pt'fg_alpha'=1.0
pt'width'=194
pt'height'=6
pt'x'=180
pt'y'=15
vl={}
vl'bg_color'=0xffffff
vl'bg_alpha'=0.3
vl'fg_color'=0xffffff
vl'fg_alpha'=1.0
vl'width'=210
vl'height'=6
vl'x'=158
vl'y'=17
function rgbtorgba(color,alpha)
return ((color / 0x10000) % 0x100) / 255., ((color / 0x100) % 0x100) / 255., (color % 0x100) / 255., alpha
end
function mysplit (inputstr, sep)
if sep == nil then
sep = ";"
end
local t={}
for str in string.gmatch(inputstr, "(^"..sep.."+)") do
table.insert(t, str)
end
return t
end

function drawbg(cr,color,alpha,typ)
local corner
r=20
local bgcolor=color
local bg
alpha=alpha
local
need noscripts combined please.

Hello everyone,

I got an .lua based NowPlaying widget for my linux mint system, run by the app Conky. It looks like this in action:

[https://i.imgur.com/0uRWo0Z.png](https://i.imgur.com/0uRWo0Z.png)

The author has retired from the forums so I can't turn to him for help. What you see is the result of 2 .lua files building the total displays. One has code to only display if audacious is running, the other only if audacious is playing. The newest edits were created by ChatGPT3.5 and probably look ridiculous to a live coder. It did get the time remaining, numeric volume percentage, and volume bar coded and working, but cannot combine any of these features with the main .lua without breaking it so that nothing at all displays.

I would like to slowly try to merge these two .lua noscripts, and would like to start with the routine to display the time remaining on currently playing track that counts down each passing second. That is in this .lua:

require 'cairo'

-- Function to check if Audacious is playing
function is_audacious_playing()
local status = exec_command("playerctl -p audacious status")
return status:match("Playing")
end

-- Main function for Conky
function conky_main()
if conky_window == nil or not is_audacious_playing() then
return
end

local surface = cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, conky_window.width, conky_window.height)
local cr = cairo_create(surface)

-- Draw volume bar and remaining time
draw_volume_bar(cr)
draw_remaining_time(cr)


cairo_destroy(cr)
cairo_surface_destroy(surface)
collectgarbage()
end

-- Function to execute shell command and get output
function exec_command(command)
local handle = io.popen(command)
local result = handle:read("*a")
handle:close()
return result
end

-- Function to get the current volume
function get_volume()
local command = "pactl get-sink-volume @DEFAULT_SINK@ | awk '{print $5}'"
local output = exec_command(command)
return tonumber(output:gsub("%%", "") or "0")
end

-- Function to convert RGB color to RGBA
function rgb_to_rgba(color, alpha)
return ((color / 0x10000) % 0x100) / 255., ((color / 0x100) % 0x100) / 255., (color % 0x100) / 255., alpha
end

-- Draw the volume bar and numeric volume display
function draw_volume_bar(cr)
local volume = get_volume()
local pct = volume / 100
local bar_properties = {
x = 164, -- X position of the bar
y = conky_window.height - 42, -- Y position of the bar
width = conky_window.width - 232, -- Width of the bar
height = 6 -- Height of the bar
}

-- Draw the background of the volume bar
cairo_set_source_rgba(cr, rgb_to_rgba(0xffffff, 0.3)) -- White color with 0.3 alpha
cairo_rectangle(cr, bar_properties.x, bar_properties.y, bar_properties.width, bar_properties.height)
cairo_fill(cr)

-- Draw the filled portion of the volume bar
local filled_width = pct * bar_properties.width
cairo_set_source_rgba(cr, rgb_to_rgba(0xFFFFFF, 1)) -- White color
cairo_rectangle(cr, bar_properties.x, bar_properties.y, filled_width, bar_properties.height)
cairo_fill(cr)

-- Draw the numeric volume value
local volume_text = tostring(volume) .. "%"
local x = bar_properties.x + bar_properties.width - 102 -- Adjust the x position for the text
local y = bar_properties.y + bar_properties.height / 2 - 8 -- Adjust the y position for the text

cairo_set_source_rgba(cr, 1, 1, 1, 1) -- White color for the text
cairo_select_font_face(cr, "Neon 80s", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL)
cairo_set_font_size(cr, 12)
cairo_move_to(cr, x, y)
cairo_show_text(cr, volume_text)
cairo_stroke(cr)
end

-- Function to get the current position of the track
function get_current_position()
local command = "playerctl position"
local output = exec_command(command)
return tonumber(output) or 0
end

-- Function to get the total duration of the track
function get_total_duration()
local command = "playerctl metadata mpris:length"
local output = exec_command(command)
return tonumber(output) / 1000000 or 0 -- Convert from microseconds to seconds
end

-- Function to convert seconds to HH:MM:SS or MM:SS format
function seconds_to_time(seconds)
local hours = math.floor(seconds / 3600)
local minutes = math.floor((seconds % 3600) / 60)
local secs = math.floor(seconds % 60)

if hours > 0 then
-- Format as HH:MM:SS if there are hours
return string.format("%d:%02d:%02d", hours, minutes, secs)
else
-- Format as MM:SS if there are no hours
return string.format("%02d:%02d", minutes, secs)
end
end

-- Function to draw the remaining track time as a numerical value
function draw_remaining_time(cr)
local current_position = get_current_position()
local total_duration = get_total_duration()

-- Calculate remaining time
local remaining_time = total_duration - current_position

-- Convert remaining time to appropriate format
local remaining_text = seconds_to_time(remaining_time)

-- Add "-" sign before the time
remaining_text = "-" .. remaining_text

-- Adjust position
local x = 20 + (conky_window.width - 40) / 2 -- Center the text horizontally
local y = conky_window.height - 50 - 4 -- Position 14 pixels above the volume bar

-- Modify these values to move the text
x = x + 32 -- Adjust horizontal position
y = y - 16 -- Adjust vertical position (subtract to move up)

-- Draw the white text on top
cairo_set_source_rgba(cr, 1, 1, 1, 1) -- White color
cairo_select_font_face(cr, "Neon 80s", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL)
cairo_set_font_size(cr, 12)
cairo_move_to(cr, x, y) -- Original position for white text
cairo_show_text(cr, remaining_text)
cairo_stroke(cr)

-- Draw the black stroke text second
cairo_set_source_rgba(cr, rgb_to_rgba(0x000000, 1)) -- Black color
cairo_move_to(cr, x + 1, y + 1) -- Offset the black text slightly
cairo_show_text(cr)
cairo_stroke(cr)
end


I would like the time remaining display removed from the above and added to this .lua please:

require 'cairo'
require "imlib2"
home_path = os.getenv ('HOME')
-- Hier den genutzen Pfad zum Conky Verzeichnis eintragen / Enter the used path to the Conky directory here
conky_path = home_path..'/.conky/NowPlayingConky/'
-- Ende Pfad zum Conky Verzeichnis / End Path
image_path = '/tmp/'
pt={}
pt['bg_color']=0xffffff
pt['bg_alpha']=0.3
pt['fg_color']=0xffffff
pt['fg_alpha']=1.0
pt['width']=194
pt['height']=6
pt['x']=180
pt['y']=15
vl={}
vl['bg_color']=0xffffff
vl['bg_alpha']=0.3
vl['fg_color']=0xffffff
vl['fg_alpha']=1.0
vl['width']=210
vl['height']=6
vl['x']=158
vl['y']=17
function rgb_to_rgba(color,alpha)
return ((color / 0x10000) % 0x100) / 255., ((color / 0x100) % 0x100) / 255., (color % 0x100) / 255., alpha
end
function mysplit (inputstr, sep)
if sep == nil then
sep = ";"
end
local t={}
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
table.insert(t, str)
end
return t
end

function draw_bg(cr,color,alpha,typ)
local corner_r=20
local bg_color=color
local bg_alpha=alpha
local
w=conky_window.width
local h=conky_window.height
cairo_set_source_rgba(cr,rgb_to_rgba(bg_color,bg_alpha))
cairo_move_to(cr,corner_r,0)
cairo_line_to(cr,w-corner_r,0)
cairo_curve_to(cr,w,0,w,0,w,corner_r)
cairo_line_to(cr,w,h-corner_r)
cairo_curve_to(cr,w,h,w,h,w-corner_r,h)
cairo_line_to(cr,corner_r,h)
cairo_curve_to(cr,0,h,0,h,0,h-corner_r)
cairo_line_to(cr,0,corner_r)
cairo_curve_to(cr,0,0,0,0,corner_r,0)
cairo_close_path(cr)

if typ==1 then
cairo_fill(cr)
else
cairo_stroke(cr)
end
end

function fDrawImage(cr,path,x,y,w,h)
cairo_save (cr)
local img = cairo_image_surface_create_from_png(path)
local w_img, h_img = cairo_image_surface_get_width(img), cairo_image_surface_get_height(img)
cairo_translate (cr, x, y)
cairo_scale (cr, w/w_img, h/h_img)
cairo_set_source_surface (cr, img, -w_img/2, -h_img/2)
cairo_paint (cr)
cairo_surface_destroy (img)
collectgarbage ()
cairo_restore (cr)
end
function draw_bar(cr,pct,pt)
local bgc, bga, fgc, fga=pt['bg_color'], pt['bg_alpha'], pt['fg_color'], pt['fg_alpha']
local w=pct*pt['width']
local x=pt['x']
local y=pt['y'] + 6 -- Lower the bar by 8 pixels
-- Background
cairo_rectangle(cr, x, y, pt['width'], pt['height'])
cairo_set_source_rgba(cr,rgb_to_rgba(bgc,bga))
cairo_fill(cr)
-- Indicator
cairo_rectangle(cr, x, y, w, pt['height'])
cairo_set_source_rgba(cr,rgb_to_rgba(fgc,fga))
cairo_fill(cr)
cairo_stroke (cr)
end
function write_text(cr, x, y, text, f)
--write_text(cr, x, y, text, {})
--font attributes (Schriftattribute zuweisen oder default Werte annehmen)
local font=f.font or "Neon 80s"
local size=f.size or 10
local align=f.align or 'l'
local bold=f.bold or false
local ital=f.italic or false
local color=f.color or "0xffffff"
local slant=CAIRO_FONT_SLANT_NORMAL
if ital then slant=CAIRO_FONT_SLANT_ITALIC end
local weight=CAIRO_FONT_WEIGHT_NORMAL
if bold then weight=CAIRO_FONT_WEIGHT_BOLD end

--Text Size (Textgröße für die Plazierung bestimmen.)
local x_a=0
local y_a=0
local te = cairo_text_extents_t:create()
tolua.takeownership(te)
cairo_select_font_face (cr, font, slant, weight)
cairo_set_font_size (cr, size)
cairo_text_extents (cr, text, te)

--Text Position
if align=='c' then
x_a = -(te.width/2+te.x_bearing)
y_a = -(te.height/2+te.y_bearing)
end
if align=='r' then
x_a = -(te.width+te.x_bearing)
--y_a = -(te.height+te.y_bearing)
end

--Schadow 1 Pixel (Schatten für den Text um 1 Pixel versetzt)
cairo_set_source_rgba(cr, rgb_to_rgba(0x000000,1))

cairo_move_to (cr, x+1+x_a, y+1+y_a)
cairo_show_text (cr, text)
cairo_stroke(cr)

-- Now Text on Top (nun den Text oben drauf)
cairo_set_source_rgba(cr, rgb_to_rgba(color,1))
cairo_move_to (cr, x+x_a, y+y_a)
cairo_show_text (cr, text)
cairo_stroke(cr)
end

function adjust_time_format(time_str)
local hours, minutes, seconds = 0, 0, 0

-- Extract hours, minutes, and seconds
if string.match(time_str, ":") then
if #time_str > 5 then -- If the format is already HH:MM:SS
hours, minutes, seconds = string.match(time_str, "(%d+):(%d+):(%d+)")
else -- If the format is MM:SS
minutes, seconds = string.match(time_str, "(%d+):(%d+)")
minutes = tonumber(minutes)
seconds = tonumber(seconds)
end
end

-- Convert to numbers
hours = tonumber(hours)
minutes =
tonumber(minutes)

-- Add HH if minutes > 59
if minutes > 59 then
hours = math.floor(minutes / 60)
minutes = minutes % 60
end

-- Return the adjusted time string
if hours > 0 then
return string.format("%02d:%02d:%02d", hours, minutes, seconds)
else
return string.format("%02d:%02d", minutes, seconds)
end
end

function conky_main()
function running(cr,player) -- is Player running? / läuft der Player?
local handle = io.popen("ps -U root -u root -N | awk '/"..player.."/{print $4}'")
local result = handle:read()
handle:close()
if result == player then
daten = mysplit (conky_parse('${exec bash '..conky_path..'mpris.sh '..player..'}')) -- $laenge";"$position";"$artist";"$titel";"$positionZeit";"$laengeZeit";"$volume
--print(daten[1])
if (daten[1]~="stopped") then
color=0xffffff alpha=0.1 typ=1
-- draw_bg(cr,color,alpha,typ) -- Funktion Hintergrund Conky Bereich / Function Backgrounds Conky Area
color=0xffffff alpha=0.8 typ=2
draw_bg(cr,color,alpha,typ) --zeichne Linie um den Bereich / Draw line around Conky Area
write_text(cr, 130,84,daten[3], {font="Neon 80s", size=22, align="l"}) -- artist
write_text(cr, 134,106,daten[8], {font="Neon 80s", size=16, align="l"}) --album
write_text(cr, 134,126,daten[4], {font="Neon 80s", size=16, align="l"}) -- noscript
write_text(cr, 145,28,daten[5], {font="Neon 80s", size=12, align="l"}) -- position

-- Adjust datum[6] time format if needed
local adjusted_time = adjust_time_format(daten[6])
write_text(cr, 420,28,adjusted_time, {font="Neon 80s", size=12, align="r"}) -- length

write_text(cr, 154, 55, "🔈", {font = "Font Awesome 6 Free Solid", size = 15, align = "l"})
write_text(cr, 388, 55, "🔊", {font = "Font Awesome 6 Free Solid", size = 15, align = "l"})
value=tonumber(daten[2])
total=tonumber(daten[1])
if (value == nil or total == nil) then
pct=1
else
pct=value/total
draw_bar(cr,pct,pt)
-- volume=tonumber(daten[7])
-- draw_bar(cr,volume,vl)
fDrawImage(cr,'/tmp/tmp.png',70,70,120,120)
end
end
end
end
if conky_window==nil then return end
local cs=cairo_xlib_surface_create(conky_window.display,conky_window.drawable,conky_window.visual, conky_window.width,conky_window.height)
local cr=cairo_create(cs)
local updates=conky_parse('${updates}')
update_num=tonumber(updates)
if update_num>5 then
-- Player Auswahl. Jeder mpris unterstützende Player ist möglich. / Player selection. Any mpris supporting player is possible.
player="audacious"

running(cr,player)
end

cairo_surface_destroy(cs)
cairo_destroy(cr)
end







https://redd.it/1f0prwe
@r_lua
got a question for the smart coders of reddit!

i have no coding experience and i want to learn Lua/Luau as fast and as best as possible got any suggestions?

https://redd.it/1f0wo2n
@r_lua
How can I work with pictures with lua, like with pillow in python

How can I work with pictures with lua, like with pillow in python

https://redd.it/1f11zcg
@r_lua
How do i learn lua very easily any advice? im a begginer like straight up begginner and i want to learn lua in a easy way(if any one insisting on teaching me personally in discord it would be so much helpfull i find my self good with people interacting and teaching me themselves)

Any one deciding on to help me learn lua? im planning on making a game first on roblox then learn other programming languages im planning so far on being a software engineer i really have a passion on it,any one mind helping? it would be helpfull alot

https://redd.it/1f15wbn
@r_lua
I edited a great picture
https://redd.it/1f1kf1r
@r_lua
Custom Love2d UI syntax :D
https://redd.it/1f1mqp8
@r_lua
Where are Lua modules stored?

For example, where is math.lua module from standard library stored on my filesystem? Module that exposes functions for mathematical operations.

I'm learning Lua on Windows 10.

https://redd.it/1f2gusc
@r_lua
How do I contribute to lua?

Hello. I am trying to contribute to the Lua project by fixing a bug? How do I do this? I could not find any information on how to do so.

Thanks.

https://redd.it/1f2kzkk
@r_lua
Best VSCode Extension for Universal use of Lua?

Pretty much the noscript. I've pretty much only have used Luau inside of Roblox Studio, but I've been finding myself using standard Lua a lot more lately for everything from personal data science hobby projects to mod development like FiveM. Are there any good Lua extensions just for autocomplete?? Like all of the methods available, also too, when I write a function or a loop, I'd like the "end" to automatically be inserted. I've tried using the extension by the user "sumneko," but for one it seems like it's pretty opinionated, and two, it doesn't autocomplete my functions or loops. Any other options?? Or am I stuck diving into a journey of learning how to make an extension?? TIA!!!

https://redd.it/1f2n4xg
@r_lua
Help

im coding a roblox game rn and i have a system where when you buy an upgrade and you click something you should get 2 of those things but for some reason when you buy the upgrade and it deducts your currency as soon as you click you get all your currency back i hav been troubleshooting for a while heres the code for the 3 main aspects of it local player = game.Players.LocalPlayer

local leaderstats = player:WaitForChild("leaderstats")

local crystals = leaderstats:WaitForChild("Crystals")



-- References to UI elements

local shopFrame = noscript.Parent

local buyButton = shopFrame:FindFirstChild("BuyButton")

local priceLabel = shopFrame:FindFirstChild("PriceLabel")



-- Initial upgrade values

local upgradeLevel = 0

local basePrice = 100

local priceIncrement = 100

local maxPrice = 5000



-- Function to update the price label

local function updateUI()

local currentPrice = basePrice + (upgradeLevel * priceIncrement)

priceLabel.Text = "Upgrade Price: " .. currentPrice .. " Crystals"

end



-- Function to handle button click and purchase

local function onBuyButtonClick()

local currentPrice = basePrice + (upgradeLevel * priceIncrement)



if crystals.Value >= currentPrice and currentPrice <= maxPrice then

-- Deduct crystals and update upgrade level

crystals.Value = crystals.Value - currentPrice

upgradeLevel = upgradeLevel + 1



-- Notify server to update crystal gain per click

game.ReplicatedStorage.UpgradeEvent:FireServer(upgradeLevel)



-- Update UI with new values

updateUI()

end

end



-- Connect the button click event to the function

buyButton.MouseButton1Click:Connect(onBuyButtonClick)



-- Initial UI setup

updateUI()

thats for the shop ui and its a local noscript


local ReplicatedStorage = game:GetService("ReplicatedStorage")

local upgradeEvent = ReplicatedStorage:WaitForChild("UpgradeEvent")



-- Function to handle upgrades

local function onUpgradeRequested(player, upgradeLevel)

local leaderstats = player:FindFirstChild("leaderstats")

local crystals = leaderstats and leaderstats:FindFirstChild("Crystals")



if crystals then

-- Calculate new crystals per click

local baseCrystalsPerClick = 1

local newCrystalsPerClick = baseCrystalsPerClick + upgradeLevel



-- Update the player's data (in this case, updating an attribute)

player:SetAttribute("CrystalsPerClick", newCrystalsPerClick)



-- Optionally, you can save this data to a datastore here if needed

end

end



-- Connect RemoteEvent to the function

upgradeEvent.OnServerEvent:Connect(onUpgradeRequested)

this is the server noscript thing and it is a noscript

local crystal = noscript.Parent

local clickDetector = crystal:FindFirstChildOfClass("ClickDetector")



-- Function to handle crystal click

local function onClick(player)

local leaderstats = player:FindFirstChild("leaderstats")

local crystals = leaderstats and leaderstats:FindFirstChild("Crystals")



if crystals then

-- Get the number of crystals per click

local crystalsPerClick = player:GetAttribute("CrystalsPerClick") or 1



-- Add the appropriate number of crystals to the player's count

crystals.Value = crystals.Value + crystalsPerClick

end

end



-- Connect the click event to the function

clickDetector.MouseClick:Connect(onClick)

and that is the click noscript so when you click the thing you get the stuff anyone have any idea why its glitching?

https://redd.it/1f2tqag
@r_lua
What does require('ustring:ustring') mean?

What does require('ustring:ustring') mean?

With this tree, what should be indicated in package.path so that require('ustring:ustring')does not produce an error?
Engines
└── LuaCommon
├── lualib
├── ustring
└── ustring.lua


https://redd.it/1f3w9f5
@r_lua
Can anyone help me with decrypting yft files

I have encrypted yft files and i want to decrypt it can anyone help me please

https://redd.it/1f4iw2f
@r_lua
So hard finding good tutorials on Lua Classic OOP library by rxi

Generally speaking teaching material and examples for Lua online is very minimal. I was recently following a tutorial that used rxi's classic library (https://github.com/rxi/classic) to implement simple OOP for Lua.

I am trying to find more information and examples of this library in use. I was really hoping for a couple more tutorials or maybe a video.

I am coming up blank. Maybe you all know of something. Seems like google is useless these days!

https://redd.it/1f4k4x7
@r_lua
Compiling Luau statically on Windows

I wanted to embed luau into my app statically on windows.

Luau doesnt have a documentation for that, nor any good help threads about that.
Asking questions on github discussions will make the thread empty for millennials.

So, I download luau's source code, create a VisualStudio project via cmake (because obviously they dont want to support windows that much), build the required projects (Luau.VM and Luau.Compiler) aaaaand.... nothing.

It generates the libraries but the libs itself arent compatible with msvc.
It builds with MSVCRT lib (/MD; /MDd) by default instead of LIBCMT.
Because of that (and a lack of dlls), Im unable to use luau on my machine.

I tried going with cmake but it instead generates mingw shared libs which are:

not compatible with msvc
not static

Any help?

https://redd.it/1f4tx2k
@r_lua