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

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

Powered by : @r_channels & @reddit2telegram
Download Telegram
FishBots - a tiny Lua coding game
https://redd.it/1jdh061
@r_lua
My "Bullet" doesn't deal any damage on collision.

So im trying to make a gun/blunderbuss in roblox and everything works just fine apart from the damage, i've tried a lot of things to fix it but nothing worked, someone help me Please.


This is the Script:

`local tool = noscript.Parent`

`local bulletsFolder = noscript.Parent:FindFirstChild("Bullets")`



`function createBullet(bulletPosition)`

`local Bullet = Instance.New("Part", bulletsFolder)`

`Bullet.CFrame = CFrame.new(bulletPosition)`

[`Bullet.Name`](http://Bullet.Name) `= "Bullet"`

`Bullet.Size = Vector3.new(0.1,0.1,0.1)`

`Bullet.BrickColor = BrickColor.new("Black metallic")`

`Bullet.Shape = Enum.PartType.Ball`

`Bullet.CanCollide = true`

`Bullet.Transparency = 0`

`Bullet.BottomSurface = Enum.SurfaceType.Smooth`

`Bullet.TopSurface = Enum.SurfaceType.Smooth`

`Bullet.Anchored = true`



`game.Debris:AddItem(Bullet, 10)`





`end`



`-- raycasting`

`noscript.Parent.Shoot.OnServerEvent:Connect(function(player, mousePosition)`

`local raycastParams = RaycastParams.new()`

`raycastParams.FilterDescendantsInstances = {player.Character}`

`raycastParams.FilterType = Enum.RaycastFilterType.Exclude`



`local raycastResult = workspace:Raycast(tool.Handle.Barrel.Position,(mousePosition - tool.Handle.Barrel.Position) * 300, raycastParams)`



`if raycastResult.Position then`

`createBullet(raycastResult.Position)`

`end`



`if raycastResult then`

`local raycastInstance = raycastResult.Instance`

`local model = raycastInstance:FindFirstAncestorOfClass("Model")`



`if model then`

`if model:FindFirstChild("Humanoid") then`

`if` [`raycastInstance.Name`](http://raycastInstance.Name) `=="Head" then`

`model:FindFirstChild("Humanoid"):TakeDamage(40)`

`else`

`model:FindFirstChild("Humanoid"):TakeDamage(20)`

`end`

`end`

`end`

`end`



`end)`

and this is the Local Script:

`local userInputService = game:GetService("UserInputService") --UIS`



`local player = game.Players.LocalPlayer --player`

`local mouse = player:GetMouse() -- mouse`



`local tool = noscript.Parent`

`local debounce = false`



`local ammo = 1`

`local MaxAmmo = 8`

`local reloading = false`

`local isEquipped = false`



`--Reloading`

`local function reload()`

`if reloading == false and isEquipped and MaxAmmo > 0 then`

`reloading = true`

`tool.Sounds["Gun Reload"]:Play()`

`task.wait(1.987)`

`ammo = 1`

`MaxAmmo -= 1`

`player.PlayerGui.AmmoGui.Frame.TextLabel.Text = "Ammo: "..ammo.."/"..MaxAmmo`

`reloading = false`

`end`

`end`



`--Bullet`

`local function createBullet()`

`local Bullet = Instance.new("Part")`

`Bullet.CFrame = CFrame.new(tool.Handle.Position, mouse.Hit.Position)`

[`Bullet.Name`](http://Bullet.Name) `= "Bullet"`

`Bullet.Size = Vector3.new(0.7,0.7,0.7)`

`Bullet.BrickColor = BrickColor.new("Black")`

`Bullet.CanCollide = true`

`Bullet.Transparency = 0`

`Bullet.BottomSurface = Enum.SurfaceType.Smooth`

`Bullet.TopSurface = Enum.SurfaceType.Smooth`

`Bullet.Shape = Enum.PartType.Ball`



`local bodyVelocity = Instance.new("BodyVelocity")`

`bodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)`

`bodyVelocity.P = math.huge`

`bodyVelocity.Velocity = mouse.UnitRay.Direction * 300`



`Bullet.Parent = game.Workspace`

`bodyVelocity.Parent = Bullet`



`game.Debris:AddItem(Bullet, 3)`

`end`



`-- Shooting`

`tool.Activated:Connect(function()`

`if debounce == false and ammo > 0 and reloading == false then`

`debounce = true`

`ammo -= 1`

`createBullet()`

`tool.Shoot:FireServer(mouse.Hit.Position)`

`tool.Sounds["Gun Shot"]:Play()`

`player.PlayerGui.AmmoGui.Frame.TextLabel.Text = "Ammo: "..ammo.."/"..MaxAmmo`

`task.wait(1.978)`

`debounce = false`

`elseif ammo <= 0 and reloading == false then`

`reload()`

`end`

`end)`



`-- UIS Reload`

`userInputService.InputBegan:Connect(function(inputObject, isTyping)`

`if isTyping then return end`

`if inputObject.KeyCode == Enum.KeyCode.R then`

`reload()`

`end`

`end)`



`-- Equip
function`

`tool.Equipped:Connect(function()`

`isEquipped = true`

`tool.Sounds["Gun Equip"]:Play()`

`mouse.Icon = "rbxassetid://"`

`player.PlayerGui.AmmoGui.Enabled = true`

`end)`



`tool.Unequipped:Connect(function()`

`isEquipped = false`

`mouse.Icon = "rbxassetid://"`

`player.PlayerGui.AmmoGui.Enabled = false`

`end)`







https://redd.it/1jdll70
@r_lua
Could i do this more "compact"? or just how it is now?
https://redd.it/1jdny7d
@r_lua
Lua web playground (like Go playground)
https://redd.it/1jdt9yu
@r_lua
My If Statement only runs the First Block of code whether correct or not.

My If Statement will ignore any defined Variables, instead it will only run the first block of code. This code is the only code in the game (I am a beginner) and I am trying to make it work

local MyVarible = A

if MyVarible == B then

print("Incorrect IF")

elseif MyVariable == A then

print("Correct If")

end

Plz help. Thanks

https://redd.it/1jdtwpp
@r_lua
LuaRT - Windows programming framework

https://preview.redd.it/9e1upzpdg8pb1.png?width=494&format=png&auto=webp&s=49c295d5e8d9dcd3bf974b9afafc14d3fc6d21da

Lua^(rt) is a free, open-source programming framework built on Lua, designed for Windows application development and released under the MIT license I just released Lua^(rt) 1.9.5, and I think it's time to give you an update on the current status of the project.

What is Lua^(rt)
Lua^(rt) extends Lua -a language valued for its beginner-friendly syntax and simplicity- to create console and desktop applications on Windows. It includes runtime modules and tools to make development accessible for newcomers while supporting complex tasks with minimal effort.

Key Features

Beginner-Friendly: Lua’s straightforward syntax makes Lua^(rt) approachable for novices, while still enabling complex tasks—like crafting GUIs or handling web requests—with concise code.
Lightweight Runtime: The Lua^(rt) runtime is compact and self-contained, relying on no external libraries, ensuring minimal overhead and easy deployment.
Object-Oriented Programming: Lua^(rt) enhances Lua with robust OOP support, including multilevel inheritance, mixins, constructors, destructors, properties, and more, for structured and reusable code.
Asynchronous Programming: Lua^(rt) includes a Taskobject for asynchronous operations, supporting async/await/after paradigms to simplify non-blocking code (e.g., running tasks in the background or scheduling delayed actions).
Batteries Included: Lua^(rt) contains lots of modules to cover most of today’s programming tasks, such as: json data parsing, audio playing and recording, clipboard access, Windows registry management, process control, compression, sqlite for database operations, C FFI module to call C functions from your Lua noscripts, and more ...
Enhanced UI Module: The ui module supports modern Windows features:
Theme Support: Adapts to Windows light/dark themes.
HighDPI support
WebView: Embeds WebView2 for displaying web content, and interact with it from Lua
Hardware-accelerated Direct2D rendering with the Canvaswidget
Bundled Development Tools: Lua^(rt) comes with its own suite of tools:
Lua^(rt) Studio IDE: A dedicated environment for writing and debugging Lua^(rt) noscripts.
RTBuilder: A RAD (Rapid Application Development) tool for visually designing GUI applications.
rtc: A compiler to generate standalone executables with embedded content, simplifying distribution.
Documentation: A thorough guide (over 1,000 pages) covers modules, examples, and tutorials,...

Community Resources: A forum at https://community.luart.org provides a space for support and discussion, as well as a Discord server

Purpose and Use

Lua^(rt) leverages Lua’s ease of use and versatility for Windows programming, enhanced by modern features and development tools.

I built this framework to propose a coherent Lua ecosystem for Windows operating systems, aiming to simplify Windows development. It’s suited for beginners building their first apps or experienced users tackling advanced projects, and it’s open to feedback or contributions.

For more details, the official website is a good starting point. I’d be interested in hearing from anyone who tries it or has questions.

Regards,

Samir

https://redd.it/1je3niy
@r_lua
Possible error when compiling program

I'm writing an interpreter and i'm trying to have the output bytecodes be 1:1 with the official luac using the 5.4.7 luac on the following program gives me these output luac -l -l -p test_lua/chapter9/upvalues.lua

g1, g2 = 1, 2
local up1, up2, up3, up4 = 11, 12, 13, 14
local print = print
local function foo()
local l1, l2 = 101, 102
l1, g1 = g2, l2
print(l1, g1)
-- assign to upvalues
up1, up2, up3 = l1, g1, up4
print(up1, up2, up3)
-- assign by upvalues
l1, g1, up1 = up2, up3, up4
print(l1, g1, up1)
local inner = function()
-- assign to upvalues
up1, up2, up3 = 101, g2, up4
print(up1, up2, up3)
end
inner()
end
foo()

main <testlua/chapter9/upvalues.lua:0,0> (13 instructions at 0x1433ecd0)
0+ params, 7 slots, 1 upvalue, 6 locals, 4 constants, 1 function
1 [1] VARARGPREP 0
2 [1] LOADI 0 1
3 [1] SETTABUP 0 1 2k ;
ENV "g2" 2
4 1 SETTABUP 0 0 0 ; ENV "g1"
5 [2] LOADI 0 11
6 [2] LOADI 1 12
7 [2] LOADI 2 13
8 [2] LOADI 3 14
9 [3] GETTABUP 4 0 3 ;
ENV "print"
10 23 CLOSURE 5 0 ; 0x1433f550
11 25 MOVE 6 5
12 25 CALL 6 1 1 ; 0 in 0 out
13 25 RETURN 6 1 1k ; 0 out
constants (4) for 0x1433ecd0:
0 S "g1"
1 S "g2"
2 I 2
3 S "print"
locals (6) for 0x1433ecd0:
0 up1 9 14
1 up2 9 14
2 up3 9 14
3 up4 9 14
4 print 10 14
5 foo 11 14
upvalues (1) for 0x1433ecd0:
0 ENV 1 0
function <test
lua/chapter9/upvalues.lua:4,23> (35 instructions at 0x1433f550)
0 params, 6 slots, 6 upvalues, 3 locals, 2 constants, 1 function
1 5 LOADI 0 101
2 5 LOADI 1 102
3 6 GETTABUP 2 0 1 ; ENV "g2"
4 [6] SETTABUP 0 0 1 ;
ENV "g1"
5 6 MOVE 0 2
6 7 GETUPVAL 2 1 ; print
7 7 MOVE 3 0
8 7 GETTABUP 4 0 0 ; ENV "g1"
9 [7] CALL 2 3 1 ; 2 in 0 out
10 [10] MOVE 2 0
11 [10] GETTABUP 3 0 0 ;
ENV "g1"
12 10 GETUPVAL 4 5 ; up4
13 10 SETUPVAL 4 4 ; up3
14 10 SETUPVAL 3 3 ; up2
15 10 SETUPVAL 2 2 ; up1
16 11 GETUPVAL 2 1 ; print
17 11 GETUPVAL 3 2 ; up1
18 11 GETUPVAL 4 3 ; up2
19 11 GETUPVAL 5 4 ; up3
20 11 CALL 2 4 1 ; 3 in 0 out
21 14 GETUPVAL 2 3 ; up2
22 14 GETUPVAL 3 4 ; up3
23 14 GETUPVAL 4 5 ; up4
24 14 SETUPVAL 4 2 ; up1
25 14 SETTABUP 0 0 3 ; ENV "g1"
26 [14] MOVE 0 2
27 [15] GETUPVAL 2 1 ; print
28 [15] MOVE 3 0
29 [15] GETTABUP 4 0 0 ;
ENV "g1"
30 15 GETUPVAL 5 2 ; up1
31 15 CALL 2 4 1 ; 3 in 0 out
32 21 CLOSURE 2 0 ; 0x1433fa70
33 22 MOVE 3 2
34 22 CALL 3 1 1 ; 0 in 0 out
35 23 RETURN0
constants (2) for 0x1433f550:
0 S "g1"
1 S "g2"
locals (3) for 0x1433f550:
0 l1 3 36
1 l2 3 36
2 inner 33
36
upvalues (6) for 0x1433f550:
0 ENV 0 0
1 print 1 4
2 up1 1 0
3 up2 1 1
4 up3 1 2
5 up4 1 3
function <test
lua/chapter9/upvalues.lua:17,21> (12 instructions at 0x1433fa70)
0 params, 4 slots, 6 upvalues, 0 locals, 1 constant, 0 functions
1 19 LOADI 0 101
2 19 GETTABUP 1 3 0 ; ENV "g2"
3 [19] GETUPVAL 2 4 ; up4
4 [19] SETUPVAL 2 2 ; up3
5 [19] SETUPVAL 1 1 ; up2
6 [19] SETUPVAL 0 0 ; up1
7 [20] GETUPVAL 0 5 ; print
8 [20] GETUPVAL 1 0 ; up1
9 [20] GETUPVAL 2 1 ; up2
10 [20] GETUPVAL 3 2 ; up3
11 [20] CALL 0 4 1 ; 3 in 0 out
12 [21] RETURN0
constants (1) for 0x1433fa70:
0 S "g2"
locals (0) for 0x1433fa70:
upvalues (6) for 0x1433fa70:
0 up1 0 2
1 up2 0 3
2 up3 0 4
3
ENV 0 0
4 up4 0 5
5 print 0 1

shouldn't this line 24 [14] SETUPVAL 4 2 ; up1 be 24 [14] SETUPVAL 2 4 ; up1?

https://redd.it/1je7b26
@r_lua
lua noscript

Hi I'm looking for someone who can write a trigger bot for FiveM as a Lua noscript. If you can do that and it works in the end, I would also pay for it.

https://redd.it/1jee7sz
@r_lua
Put png file in lua file is possible ?

Hello, I'm a graphic designer (so you're talking to someone stupid, who's probably going to ask stupid questions)

For a project, I need to put PNG files inside a LUA file, so as not to provide any external files other than the LUA file, but I don't know if this is possible (I hear everything and its opposite on the internet).

can someone can answer my question ? :/

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

So ive done a few LUA tutorials online (trying to learn it for ROBLOX game development) but i have learnt everything cant figure out how to make stuff. like for example, i know stuff about lua but i have no idea how to make something random that helps me practice. like i dont know how to actually noscript this stuff but i know the language idk if u guys can understand that but help pls

https://redd.it/1jey7b1
@r_lua
Scribe

Scribe provides functions to convert Lua objects to readable strings and output methods that make printing Lua tables in various formats easy.

For example, if arr = {1, 2, 3} then scribe.put("Array: %t", arr) will print "Array: [ 1, 2, 3 \]" to stdout.

Scribe gracefully handles complex tables, including ones with shared and cyclical references. The strings returned for those tables show the underlying structure in a way that is as readable as possible.

You can customise the strings returned for tables by passing a set of formatting options, and there are pre-defined options that will work for most applications. Those include printing tables on a single line, in a “pretty” format on multiple lines, or as JSON-like denoscriptors.

scribe is available as a GitHub repo. It has a permissive MIT License.

scribe can also be installed using luarocks:

luarocks install scribe

scribe is fully documented here.
We built the documentation site using Quarto.

The documentation includes a lengthy article describing how we built the module.
That tutorial might be a decent Lua 201 tutorial for those new to the language.

https://redd.it/1jf3n39
@r_lua
Beginner programmer looking for a teacher or tips

I am new to lua and coding in general, though I do have a little experience in python. I am trying to make a Roblox game. I am looking for someone to help me and teach me the coding language lua

https://redd.it/1jfgnb9
@r_lua
Help! Roblox Studio Lua!

So, before I get into this, yes I used AI, no I can't code even a little, meaning no I do not have any idea what I'm doing, but brownie points for trying, I guess?
I don't currently want to get into learning code, (I have school and other stuff, but I really wanted to get into experimenting with Studio) but unfortunately, with trying to make a Roblox game, that's required for quality. Hoping someone can help me here.
By the way! This is all happening on a test world which has nothing but a part that I'm using as a baseplate, and a humanoid named DialogueNPC in the workspace (plus spawn). The dialogue in this code is random and only for testing purposes.

I'm trying to make a dialogue work, as you can tell by the NPC's name. I already have a noscript for tweening on-screen, and a noscript for tweening off-screen. By the grace of God, they work perfectly.Still, I'll provide you with everything I have, and everything these AI's have put me through lmao. I put an image of my hierarchy, assuming you'll need it. I'll sum up the noscripts, but pretty sure you guys could probably read these like books. I broke these into many noscripts because originally when there were just two big ones, it didn't work well and I couldn't try to use my very tiny coding brain to figure out what was the problem.

**Script #1: AnimScript. (Server Script) This noscript tweens the CinemaBar1 and 2 onto the screen for the player, no issues but I don't know if it conflicts with anything, so I'm giving it to you.**
\-- Script inside DialogueUI (AnimScript)



local Torso = workspace.DialogueNPC:WaitForChild("Torso")

local EPrompt = Torso:WaitForChild("EPrompt")



local dialogueUI = noscript.Parent -- Get DialogueUI from noscript.Parent



local CinemaBar1 = dialogueUI:WaitForChild("CinemaBar1")

local CinemaBar2 = dialogueUI:WaitForChild("CinemaBar2")



local startPosition1 = UDim2.new(0.5, 0, 1.851, 0)

local targetPosition1 = UDim2.new(0.5, 0, 0.851, 0)



local startPosition2 = UDim2.new(0.5, 0, -1, 0)

local targetPosition2 = UDim2.new(0.5, 0, 0.066, 0)



local tweenInfo = TweenInfo.new(

1,

Enum.EasingStyle.Quad,

Enum.EasingDirection.Out,

0,

false,

0

)



local function onPromptTriggered(player) -- Player is passed in

local tweenService = game:GetService("TweenService")

local tween1 = tweenService:Create(CinemaBar1, tweenInfo, {Position = targetPosition1})

local tween2 = tweenService:Create(CinemaBar2, tweenInfo, {Position = targetPosition2})



CinemaBar1.Position = startPosition1

CinemaBar2.Position = startPosition2



tween1:Play()

tween2:Play()



\-- Signal Dialogue Script

local dialogueEvent = game.ReplicatedStorage:WaitForChild("StartDialogueEvent")

dialogueEvent:FireClient(player) -- Fire the event to the client

end



EPrompt.Triggered:Connect(onPromptTriggered)

**Script #2: AnimScriptReverse. (Server Script) This does what the name says. Just the reverse of the AnimScript. Brings CinemaBar1 & 2 off screen, then turns the GUI to false.**
off-screen.
\-- Script inside DialogueUI (AnimScriptReverse)



local dialogueUI = noscript.Parent

local dialogueScript = dialogueUI:WaitForChild("DialogueButtonScript")

local dialogueModule = require(dialogueUI:WaitForChild("DialogueModule")) -- Require the module



local CinemaBar1 = dialogueUI:WaitForChild("CinemaBar1")

local CinemaBar2 = dialogueUI:WaitForChild("CinemaBar2")



local startPosition1 = UDim2.new(0.5, 0, 1.851, 0)

local targetPosition1 = UDim2.new(0.5, 0, 0.851, 0)



local startPosition2 = UDim2.new(0.5, 0, -1, 0)

local targetPosition2 = UDim2.new(0.5, 0, 0.066, 0)



local tweenInfo = TweenInfo.new(

1,

Enum.EasingStyle.Quad,

Enum.EasingDirection.Out,

0,

false,

0

)



local function resetDialogue()

dialogueUI.Enabled = true

dialogueModule.currentDialogueState = "Greeting" -- Use the module variable

dialogueScript.updateDialogue()

end



local function reverseAnimation()

local tweenService = game:GetService("TweenService")

local tween1 = tweenService:Create(CinemaBar1, tweenInfo, {Position =
startPosition1})

local tween2 = tweenService:Create(CinemaBar2, tweenInfo, {Position = startPosition2})



tween1:Play()

tween2:Play()



tween2.Completed:Connect(function()

dialogueUI.Enabled = false

resetDialogue()

end)

end



\-- Connect to a RemoteEvent (we'll fire this from the dialogue noscript)

local reverseEvent = game.ReplicatedStorage:WaitForChild("ReverseDialogueEvent")

reverseEvent.OnServerEvent:Connect(reverseAnimation)

**Script #3: DialogueModule. (Module Script) I'll be honest. I have no idea what this does, or why it's needed. It's just there because the AI told me to.**
\-- DialogueModule



local DialogueModule = {}



DialogueModule.currentDialogueState = "Greeting" -- Starting state



return DialogueModule

**Script #4: DialogueButtonScript. (Local noscript) This is where the issue is. It's not a big part, something small that prevents the whole thing from working, but essentially it holds the dialogue, creates buttons using a button template I made, and is supposed to carry out the sequence of dialogue when an option other than nextState = nil or Goodbye is pressed.**
**Issue? ::** line 76, updateDialogue()
**What is the output error? ::** it is a nil error.
Players.R1NYP00H.PlayerGui.DialogueUI.DialogueButtonScript:76: attempt to call a nil value - Client - DialogueButtonScript:76
Apparently this means its trying to call a value that's undefined? I've tried anything I know, and anything these computers can give me, and its either going way too complicated for my understanding, or doesn't work and creates more errors. This error happens when you click a text button/option that leads to more dialogue instead of closing the UI. Once again, dialogue was generated random, just for testing.


\-- LocalScript inside DialogueUI

local OptionsList = noscript.Parent:WaitForChild("CinemaBar1"):WaitForChild("OptionsList")

local DialogueOptionTemplate = OptionsList:WaitForChild("DialogueOptionTemplate")

local NPCSpeechText = noscript.Parent:WaitForChild("CinemaBar1"):WaitForChild("NPCDialogueBar"):WaitForChild("NPCSpeechText")

local UIListLayout = OptionsList:WaitForChild("UIListLayout")

local dialogueModule = require(noscript.Parent:WaitForChild("DialogueModule")) -- Require the module



\-- // Dialogue Data (your data)

local dialogueData = {

["Greeting"\] = {

npcSpeech = "Hello there, adventurer!",

options = {

{text = "Who are you?", nextState = "WhoAreYou"},

{text = "What's going on?", nextState = "WhatsGoingOn"},

{text = "Goodbye.", nextState = nil}

}

},

["WhoAreYou"\] = {

npcSpeech = "I am the friendly local guide.",

options = {

{text = "Where can you guide me?", nextState = "WhereToGuide"},

{text = "Okay, thanks.", nextState = nil}

}

},

["WhatsGoingOn"\] = {

npcSpeech = "There's a bit of trouble in town...",

options = {

{text = "Tell me more.", nextState = "TellMeMore"},

{text = "I see.", nextState = nil}

}

},

["TellMeMore"\] = {

npcSpeech = "The goblins have been stealing pies!",

options = {

{text = "I'll help!", nextState = "Help"},

{text = "That's... unfortunate.", nextState = nil}

}

},

["WhereToGuide"\] = {

npcSpeech = "I can show you the old ruins.",

options = {

{text = "Take me there!", nextState = "Goodbye"}, -- Or another state

{text = "Maybe later.", nextState = nil}

}

},

["Help"\] = {

npcSpeech = "Thank you! The bakery is just over there.",

options = {

{text = "I'm on it!", nextState = nil}

}

},

["Goodbye"\] = {

npcSpeech = "Farewell!",

options = {} -- No more options, dialogue ends

}

}



\-- Move updateDialogue() before the click event handler

local function createDialogueOptions(options)

\-- Create new options from the provided table

for _, optionData in ipairs(options) do

local newOption = DialogueOptionTemplate:Clone()

newOption.Text = optionData.text

newOption.Name = "DialogueOption_" .. _ -- Unique name



\-- Parent the button before making it
visible

newOption.Parent = OptionsList



newOption.Visible = true



\-- Connect the button click event (add your logic here)

newOption.MouseButton1Click:Connect(function()



if optionData.nextState then

dialogueModule.currentDialogueState = optionData.nextState -- Use the module variable

updateDialogue() -- THIS LINE HERE , other comments were ai, but this is me

else

\-- End dialogue and reverse animation

local reverseEvent = game.ReplicatedStorage:WaitForChild("ReverseDialogueEvent")

reverseEvent:FireServer()

end

end)

end

end



\-- Move updateDialogue() outside of createDialogueOptions()

local function updateDialogue()

local currentStateData = dialogueData[dialogueModule.currentDialogueState\] -- Use the module variable

if currentStateData then

NPCSpeechText.Text = currentStateData.npcSpeech

createDialogueOptions(currentStateData.options)

else

\-- Handle invalid state (e.g., end dialogue or show an error)

NPCSpeechText.Text = "Dialogue error."

createDialogueOptions({})

end

end



\-- Start the dialogue

updateDialogue()


pls help I beg you very very smart awesome programming people. I'm a teen with no job and no moneys I can't afford to pay for an actual noscripter for my currently nonexistent game. (under NPCDialogueBar is NPCSpeechText, its a text label and it holds the NPC's end of the dialogue. forgot that drop-down)

https://redd.it/1jfijs2
@r_lua
do you think i can optimise this code?

\--lua 5.4.2
print("write only numbers")
for i = 1,io.read() do

local file = io.open("words.txt", "r")
local word = ""
 
for i = 1,math.random(1,19999) do
word = file:read("*l")
end

local generated = {}

for i = 1, #word do
generated[i\] = word:sub(i, i)
end

local word_G = {}

for i = 1, #generated do
word_G[i\] = generated[math.random(#generated)\]
end

print(i..": "..word.." to "..table.concat(word_G))

end


https://redd.it/1jfw1ud
@r_lua
Lua is the GOAT of interpreted languages 🚀
https://redd.it/1jfyfgv
@r_lua