ok so basically
im making a module where it creates a text for game purposes of course
and i need to change a text created from that module by using a other script
(if you dont understand what i said just uh ask for me to explain it again i guess)
the module
local ChapterText = {}
function ChapterText.ClassicChapterText()
local ScreenGui = Instance.new("ScreenGui")
local CText = Instance.new("TextLabel")
ScreenGui.Parent = game.StarterGui
CText.Parent = ScreenGui
CText.Text = "Chapter #"
end
return ChapterText
so yeah
how can i do this? (and yes i know i have to require it or whatever)
Parameterize your function so that it can take a string and set the text to that.
function ChapterText.ClassicChapterText(Text: string)
local ScreenGui = Instance.new("ScreenGui")
local CText = Instance.new("TextLabel")
ScreenGui.Parent = game.StarterGui
CText.Parent = ScreenGui
CText.Text = Text
end
I fixed your script a little bit, here are some examples of what you can do.
First, you can make this function and leave it as it is,
local ChapterText = {}
function ChapterText.ClassicChapterText()
local ScreenGui = Instance.new("ScreenGui")
ScreenGui.Name = "YourScreenGuiName"
local CText = Instance.new("TextLabel")
CText.Text = "Chapter #"
ScreenGui.Parent = game.Players.LocalPlayer.PlayerGui
CText.Parent = ScreenGui
end
return ChapterText
and in the other script(must be local)
local gui = game.Players.LocalPlayer.PlayerGui:FindFirstChild("YourScreenGuiName")
if gui then
if gui:FindFirstChild("TextLabel") then
gui:FindFirstChild("TextLabel").Text = "YourTextHere"
end
end
You can basically change the text like this after you can create the text. (Another example is in replies)
text.ClassicChapterText is the function it looks like. You might want to return the ScreenGui so you can then access the text label. I am also not sure why you are inserting it to StarterGui, it won’t show to players until after respawn.
local Players = game:GetService("Players")
local client = Players.LocalPlayer
function ChapterText.ClassicChapterText(Text: string)
local ScreenGui = Instance.new("ScreenGui")
local CText = Instance.new("TextLabel")
ScreenGui.Parent = client.PlayerGui
CText.Parent = ScreenGui
CText.Text = Text
return ScreenGui
end
Thenn in your script you can do
local gui = text.ClassicChapterText("Chapter #423423423")
and uh, that is it. Since the function sets it for you.
local ChapterText = {}
local textcreated = false
local function CreateText(Text: string) -- This function will run if no gui has been created yet.
local ScreenGui = Instance.new("ScreenGui")
ScreenGui.Name = "TextGui"
local CText = Instance.new("TextLabel")
CText.Text = Text
ScreenGui.Parent = game.Players.LocalPlayer.PlayerGui
CText.Parent = ScreenGui
textcreated = true -- Sets the textcreated to true so it won't create another gui again.
end
function ChapterText.ClassicChapterText(Text: string)
if textcreated == false then -- Checks if there's already a gui (If the function above did not run)
CreateText(Text) -- Creates a new gui with the text
else -- If there's already a gui
local gui = game.Players.LocalPlayer.PlayerGui:FindFirstChild("TextGui") -- Finds the gui
if gui then
if gui:FindFirstChild("TextLabel") then -- Finds the textlabel
gui:FindFirstChild("TextLabel").Text = Text -- Updates the text of the textlabel to the new text.
end
end
end
end
return ChapterText
Uh no? You can just require the module and run the function, and it’ll do the job for you.
(If it already created a GUI, instead of creating a new one, it finds the GUI that’s been already created and changes the text of the TextLabel.)