#OOP (my self is returning as nil
362 messages · Page 1 of 1 (latest)
I cant see the pic well, but you seem to be calling the GetVar with dot instead of : which dosent pass in self
so either pass in self or use num:GetVar()
so when you use the dot notation
no, you need to set the metatable
or when you use the colon notation, it basiacly passes in the self in the function
just click on the image
didn't say nothing
xd
ye u just need to call the method with colons
:
num:GetVar()
ima try this I might be brain dead ty for correcting me 🙂
nope! that its my fail
try the above
you can do a num:GetVar() which is the same thing as num.GetVar(self)
its just syntactic sugar
yep
now im getting 20:03:18.372 ServerScriptService.Script:9: attempt to call missing method 'GetVar' of table - Server - Script:9
did you change anythin in the module?
I put setmetatable(MT, self)
ik but Izan told me to change it around
you wanna link self to the meta table
so the first paramter is the table and the sec is the meta
ok it got rid of the error but my self is still nil
show pic of module rq
local MT = {}
MT.__index = MT
function module.new(var1, var2)
local self = {}
setmetatable(self, MT)
self.var = var1 or nil
self.var = var2 or nil
return self
end
function MT:GetVar()
print(self)
end
return module```
print self?
wait mb
OMG
IM SO DUMB
bro
lol
I set the self.var for the other self.var
so it was returning nil
I just had to do
self.new_var = var1 or nil
self.new_var2 = var2 or nil
did u put two values?
it would override the first value but should atleast print the seconed
works but
when I was using OOP and making my functions sometimes my self would go nil
how do I fix that?
Do I just makes checks for self in my MT:Functions?
did you use dot notation?
ye when you call them
when you made them in the module did you make em with : too
do you have an example you can show?
hold up
not really cause I deleted the module cause I gave up but I had it to where it would type a self.string and tywrite it on a textlabel but i did local len = string.len(self.thread) and it kept saying that self.thread was nil and it wasnt a string
unless I did something wrong?
from my constructor
can you try to replicate the code you just talked abt
like just do a quick constructer and method
alr
give me a sec
something like this:
local MT = {}
MT.__index = MT
function module.new_string(new_string)
local self = {}
setmetatable(self, MT)
self.new_thread = new_string or "Lorem"
return self
end
function MT:TypeWrite()
local len = string.len(self.new_thread)
print(len)
end
return module ```
@vale mango
it works now for some reason but before it kept saying attempt to index nil with thread
maybe I put something wrong the last time?
maybe
oh wait a second I have the orginal script hold up I just remembered
alr
This is the orginal script:
local tw = {}
sh.__index = sh
tw.__index = tw
function sh.new_s(new_string, new_libary)
local self = setmetatable({}, sh)
self.string = new_string or "Lorem"; if type(new_string) ~= "string" then return error("Argument provided is not a string or did not provide a string!") end
self.stable = new_libary or {}; if type(new_libary) ~= "table" then return error("Argument provided is not a table or did not provide a table!") end
return self
end
function sh.new_threadObject(thread_object, new_thread, speed, sound, typewrite)
local self = setmetatable({}, tw)
self.object = thread_object or nil; if thread_object.ClassName ~= "TextLabel" then return error("Argument provided is not a TextLabel or did not provide one! ") end
self.thread = new_thread; if type(new_thread) ~= "string" then return error("Argument provided is not a string or did not provide one!") end
self.thread_speed = speed or 0; if type(speed) ~= "number" then return error("Argument provided is not a number or did not provide one!") end
self.thread_sound = sound; if sound.ClassName ~= "Sound" then return error("Argument provided is not a Sound or did not provide one!") end
self.write = typewrite or nil; if type(typewrite) ~= "boolean" then return error("Argument provided is not a boolean or did not provide a boolean!") end
return self
end
local function playSound(sound)
coroutine.create(playSound)
if sound.IsLoaded ~= true then return warn("Sound is loading or has not loaded") end
sound.Loaded:Connect(function()
sound:Play()
end)
end
function sh:play_thread()
local len = string.len(self.thread)
for i = 1, len, 1 do
self.object.Text = string.sub(self.thread, 1, i)
task.wait(self.thread_speed)
end
end
return sh ```
error in the output: 13:14:52.238 ReplicatedStorage.Modules.sh:33: invalid argument #1 to 'len' (string expected, got nil) - Client - sh:33
ye
one sec
no holdon
lemme look at this again
oh alr
ye am just sayin show me how you used it so I can see how it broke
do you not have the server script where you rquired it
something like this:
local mod = require(RS:WaitForChild("module1"))
local String = "hello"
local TL = script.Parent.TextLabel
local Sound = "Sound"
mod.new_threadObject(TL, String, 0.03, Sound, true)
mod:play_thread() ```
but it didnt work cause of the error above
local len = string.len(self.thread)
for i = 1, len, 1 do
self.object.Text = string.sub(self.thread, 1, i)
task.wait(self.thread_speed)
end
end ```
This function right here was the main function that was giving me problems
are you sure its not cuz the playthread method dosent exist in the metatalbe you linked it to
which is tw
I canhed it to sh
Changed it
local self = setmetatable({}, sh)
in new_threadObject
let me try that then
let yk if it works
now its saying
OMG
@vale mango
BRO
IT WORKS
OMG
TY
for replacing my braincells
np
wanna try it ouy?
hm?
Ill give you the newer version
sure
local tw = {}
sh.__index = sh
tw.__index = tw
function sh.new_s(new_string, new_libary)
local self = setmetatable({}, sh)
self.string = new_string or "Lorem"; if type(new_string) ~= "string" then return error("Argument provided is not a string or did not provide a string!") end
self.stable = new_libary or {}; if type(new_libary) ~= "table" then return error("Argument provided is not a table or did not provide a table!") end
return self
end
function sh.new_threadObject(thread_object, new_thread, speed, sound, typewrite)
local self = setmetatable({}, tw)
self.object = thread_object or nil; if thread_object.ClassName ~= "TextLabel" then return error("Argument provided is not a TextLabel or did not provide one! ") end
self.thread = new_thread; if type(new_thread) ~= "string" then return error("Argument provided is not a string or did not provide one!") end
self.thread_speed = speed or 0; if type(speed) ~= "number" then return error("Argument provided is not a number or did not provide one!") end
self.thread_sound = sound; if sound.ClassName ~= "Sound" then return error("Argument provided is not a Sound or did not provide one!") end
self.write = typewrite or nil; if type(typewrite) ~= "boolean" then return error("Argument provided is not a boolean or did not provide a boolean!") end
return self
end
local function playSound(sound)
coroutine.create(playSound)
if sound.IsLoaded ~= true then return warn("Sound is loading or has not loaded") end
sound.Loaded:Connect(function()
sound:Play()
end)
end
function tw:play_thread()
local len = string.len(self.thread)
for i = 1, len, 1 do
self.object.Text = string.sub(self.thread, 1, i)
task.wait(self.thread_speed)
end
end
return sh ```
only problem is I dont see play_thread for auto completion when I do
new_thread:play_thread() ```
thing is I cant test it out, cuz I dont have a sound
but holdon, lemme remove some stuff
alr
dangit
sound is not working
but ik
why
Think I can fix
all good?
local self = setmetatable({}, tw)
this line
local self = {}
setmetatable({}, tw)
so change this local self = setmetatable({}, tw)
into this local self = {}
setmetatable(self, tw)
alr
like this function sh.new_threadObject(thread_object, new_thread, speed, sound, typewrite) local self = {} setmetatable(self, tw) self.object = thread_object or nil; if thread_object.ClassName ~= "TextLabel" then return error("Argument provided is not a TextLabel or did not provide one! ") end self.thread = new_thread; if type(new_thread) ~= "string" then return error("Argument provided is not a string or did not provide one!") end self.thread_speed = speed or 0; if type(speed) ~= "number" then return error("Argument provided is not a number or did not provide one!") end self.thread_sound = sound; if sound.ClassName ~= "Sound" then return error("Argument provided is not a Sound or did not provide one!") end self.write = typewrite or nil; if type(typewrite) ~= "boolean" then return error("Argument provided is not a boolean or did not provide a boolean!") end return self end ?
nvm, now am confused
oh
wait what are you trying to fix?
Am tryna see why it aint autocompletin
ohh
alr
am getting this now
coroutine.create(playSound)
if sound.IsLoaded ~= true then return warn("Sound is loading or has not loaded") end
sound.Loaded:Connect(function()
sound:Play()
end)
end
function tw:play_thread()
local len = string.len(self.thread)
for i = 1, len, 1 do
self.object.Text = string.sub(self.thread, 1, i)
coroutine.resume(playSound(self.thread_speed))
task.wait(self.thread_speed)
end
end
return sh ``` - 20:56:43.357 ReplicatedStorage.module1:26: attempt to index number with 'IsLoaded' - Client - module1:26
so this is a bit diffrent from urs but it autocompletes for me
and wait lemme see what u tryna do with that coroutine
the coroutine create needs to be followed with coroutine resume to start it
or if u want do task.spawn to spawn the thread
I did this ``` local function playSound(sound)
coroutine.create(playSound)
if sound.IsLoaded ~= true then return warn("Sound is loading or has not loaded") end
sound.Loaded:Connect(function()
sound:Play()
end)
end
function tw:play_thread()
local len = string.len(self.thread)
for i = 1, len, 1 do
self.object.Text = string.sub(self.thread, 1, i)
coroutine.resume(playSound(self.thread_sound))
task.wait(self.thread_speed)
end
end
return sh ``` Error: 21:02:25.418 ReplicatedStorage.module1:37: missing argument #1 to 'resume' (thread expected) - Client - module1:37
with coroutine.resume you need a refernce of the coroutine
the one you made with .create
oh
wait
but why does it say thread expected (I think im just tired im sorry lol)
I lose braincells when im tired
let me figure this out rq
alr
but is the previous problem solved?
so this is a new one
o oke
facts
Alr
No error anymore
but
sound isnt playing
Updated version ``` local sh = {}
local tw = {}
sh.__index = sh
tw.__index = tw
function sh.new_s(new_string, new_libary)
local self = setmetatable({}, sh)
self.string = new_string or "Lorem"; if type(new_string) ~= "string" then return error("Argument provided is not a string or did not provide a string!") end
self.stable = new_libary or {}; if type(new_libary) ~= "table" then return error("Argument provided is not a table or did not provide a table!") end
return self
end
function sh.new_threadObject(thread_object, new_thread, speed, sound, typewrite)
local self = {}
setmetatable(self, tw)
self.object = thread_object or nil; if thread_object.ClassName ~= "TextLabel" then return error("Argument provided is not a TextLabel or did not provide one! ") end
self.thread = new_thread; if type(new_thread) ~= "string" then return error("Argument provided is not a string or did not provide one!") end
self.thread_speed = speed or 0; if type(speed) ~= "number" then return error("Argument provided is not a number or did not provide one!") end
self.thread_sound = sound; if sound.ClassName ~= "Sound" then return error("Argument provided is not a Sound or did not provide one!") end
self.write = typewrite or nil; if type(typewrite) ~= "boolean" then return error("Argument provided is not a boolean or did not provide a boolean!") end
return self
end
local function playSound(sound)
if sound.IsLoaded ~= true then return warn("Sound is loading or has not loaded") end
sound.Loaded:Connect(function()
sound:Play()
end)
end
local cor = coroutine.create(playSound)
function tw:play_thread()
local len = string.len(self.thread)
for i = 1, len, 1 do
self.object.Text = string.sub(self.thread, 1, i)
coroutine.resume(cor, self.thread_sound)
task.wait(self.thread_speed)
end
end
return sh ```
is it like a permission thing maybe
I had this problem before
I think
It has something to do with the sound being in a for do
or maybe
it is playing
its just
waiting?
im confused
But I wouldn't have to sound permissions cause its not my sound?
right?
im sure of?
what are you trying to do with this loop
because from what I remembe you can only resume a coroutine once?
oh
oh I was trying to
well I wanted to play the sound as soon as the text started
or the thread/string began at i and the string.sub was equal to -1, -1
so I used a corutine.create
I was going to use
task.spawn
why?
tbh idk I thought it ment it would start my function when the type writing effect began
I think
I might have to rewrite
why do you need a thread for it tho
why not a normal function
my self.thread or the corutine?
it is a connection afterall, why you put it in a coroutine
LOL
💀
Thats fuckin funny
we dont talk about this 
I should remove it
If it's not really giving me what I want
ye just a normal function
tbh
a coruotine thread is needed if you have a function that yileds
examples?
like a function that has a task.wait(2) in it
but if its a connection
they dont yiled
oh so when I use run service basically ?
ye
It would help you if u understood how coroutines work like step by step
nah, they tricky at first
one problem though
bro..
local tw = {}
sh.__index = sh
tw.__index = tw
function sh.new_s(new_string, new_libary)
local self = setmetatable({}, sh)
self.string = new_string or "Lorem"; if type(new_string) ~= "string" then return error("Argument provided is not a string or did not provide a string!") end
self.stable = new_libary or {}; if type(new_libary) ~= "table" then return error("Argument provided is not a table or did not provide a table!") end
return self
end
function sh.new_threadObject(thread_object, new_thread, speed, sound, typewrite)
local self = {}
setmetatable(self, tw)
self.object = thread_object or nil; if thread_object.ClassName ~= "TextLabel" then return error("Argument provided is not a TextLabel or did not provide one! ") end
self.thread = new_thread; if type(new_thread) ~= "string" then return error("Argument provided is not a string or did not provide one!") end
self.thread_speed = speed or 0; if type(speed) ~= "number" then return error("Argument provided is not a number or did not provide one!") end
self.thread_sound = sound; if sound.ClassName ~= "Sound" then return error("Argument provided is not a Sound or did not provide one!") end
self.write = typewrite or nil; if type(typewrite) ~= "boolean" then return error("Argument provided is not a boolean or did not provide a boolean!") end
return self
end
local function playSound(sound)
if sound.IsLoaded ~= true then return warn("Sound is loading or has not loaded") end
sound.Loaded:Connect(function()
sound:Play()
end)
end
function tw:play_thread()
local len = string.len(self.thread)
for i = 1, len, 1 do
self.object.Text = string.sub(self.thread, 1, i)
playSound(self.thread_sound)
task.wait(self.thread_speed)
end
end
return sh ``` I updated the script sound is still not playing
:I
🙏
error pls....??
there is no error 💀

ah sh
again why is the function in a loop
dont you need to start the sound once?
or is it liek a short sound and plays for each letter???
Because If it's not in the loop the sound wont play when the type writer effect yk types
bingo
o its a typewriter...
sound.Loaded:Connect(function()
sound:Play()
end)
** You are now Level 14! **
this makes it not fire after it loaded
yea but what about my check?
if sound.IsLoaded ~= true then return warn("Sound is loading or has not loaded") end
alr let me try
cuz the event listens for when the sound fires then it plays it
wdym event?
OH
this will listen for when the sound loaded
alr
plus it only will fire once and after it loaded it wont fire again even if you call the function
It's still not playing Do you think it's because I put it in sounds service?
bro I never touched sound service in my life...
sometimes wrong placed sounds don't play for some reason
so this aint workin?
.
no
just one
let me try typing out new words
one sec
no way
my roblox studio just crashed 
🙏
...
But I didnt wrap it in a for loop?
did u play it once then?
I ment while
yes
Maybe cause Im playing it when the player joins perhaps?
so?
only thing I added was this
local String, String2 = "hello", "Hi, my name is flower."
local TL = script.Parent.TextLabel
local Sound = SS:WaitForChild("Undertale - Flowey Talk (Normal)")
local new_thread = mod.new_threadObject(TL, String, 0.03, Sound, true)
local new_thread2 = mod.new_threadObject(TL, String, 0.03, Sound, true)
new_thread:play_thread()
new_thread2:play_thread()
no nvm think that was just my wifi
...........................................
LOL
alr slide 500 dollars
tf u think this is
** You are now Level 12! **
no you dont

let em starve