Need help for a script and fire script thing

Heyo, I’m a beginner in scripting and I do need help

So I want to know how to make it so i can activate this with different text and different text speed in a different script within the workspace in a model

local text = script.Parent

local vals = game.Workspace.values

local function writetext(msg,waiter)
	text.Text = ""
	text.Visible = true
	text.TextTransparency = 0
	for i = 1,#msg, 1 do
		script.Sound:Play()
		script.Sound.PlaybackSpeed = math.random(1100,1400)/1000
		text.Text = msg:sub(1,i)
		task.wait(waiter)
	end
end

local function endtext()
	for i = 1, 10 do
		text.TextTransparency = text.TextTransparency + 0.1
		task.wait(0.05)
	end
end

task.wait(2)
writetext("(This game is WIP, So expect some bugs)",0.025)
task.wait(3)
endtext()
task.wait(2)
writetext("no, not this place...",0.1)
task.wait(2)
writetext("...",0.025)
task.wait(0.5)
endtext()


image of the location rn and where I want scripts in to execute it (in workspace)

What is the game that holds this code

Foreboding Curiosity | Play on Roblox this is the game if you want to play it in its current state rn (not much gameplay wise is finished yet but the entities are done along with the A section) [and no there wont be seperate sections. only variants]

What is this about

I’m trying to make a unique rooms game (dont say its a doors clone the rooms by nicorocks5555 literally came before doors) that is a what if scenario if the og was recontinued and had more gameplay than just walk and hide and find batteries

and also to attempt to make rooms kinda eerie or atleast mysterious

1 Like

I’m not completely sure what are you trying to achieve, but from what I understand, I think you are trying to use the writetext function in another script; If that is indeed what you are trying to do then you should use ModuleScripts and move your function there to call it from whatever script you want, you could put this ModuleScript in ReplicatedStorage in case you want to access it from both the server and the client or just put it where the client can access it.

I would recommend that you take a look at this videos in case that you don’t know anything about ModuleScripts.
https://m.youtube.com/watch?v=foKFpXZYXPk

https://m.youtube.com/watch?v=xYMbv8cS1os

Additionally, you could move the “values” folder you have in Workspace to another container like ReplicatedStorage. And also, im not sure if you are implying that you want to store scripts in workspace, I wouldn’t recommend doing that for organization purposes.

If i’m getting your request wrong feel free to correct me since i’m not sure if this is what you want.

Hello, I do not really know if it works for you, but you can try to rewrite some parts of my code with your, for greater convenienceю

you can try to add inside your Text object (where your current script is), insert a BindableFunction.

like a local functions with changable variables (function input), you just fire the local functions with right input and just assign it whatever you need, in text property, etc. and :Invoke when you need.

local text = script.Parent
local vals = game.Workspace.values
local bindable = script.Parent:WaitForChild("WriteTextFunction")

local function writetext(msg, waiter)
	text.Text = ""
	text.Visible = true
	text.TextTransparency = 0

	for i = 1, #msg, 1 do
		script.Sound:Play()
		script.Sound.PlaybackSpeed = math.random(1100, 1400) / 1000
		text.Text = msg:sub(1, i)
		task.wait(waiter)
	end
end

local function endtext()
	for i = 1, 10 do
		text.TextTransparency = text.TextTransparency + 0.1
		task.wait(0.05)
	end
	text.Visible = false
end


bindable.OnInvoke = function(action, msg, waiter)
	if action == "write" then
		writetext(msg, waiter)
	elseif action == "fade" then
		endtext()
	end
end

And there is an example how the other script will looks like:

  1. At first, use what info you need to show/display;
  1. At second, the second thing is fade/write, etc.
local textLabel = textModel:WaitForChild("Text")  -- <-- change the object name how u need

task.wait(2)
writeTextFunc:Invoke("write", "(This game is WIP, So expect some bugs)", 0.05)

task.wait(3)
writeTextFunc:Invoke("fade")

task.wait(1)
writeTextFunc:Invoke("write", "no, not this place..."", 0.01)

The usage of the BindableEvent is perfect because it allows one script to trigger a function inside another script how many times you need, not like the “basic” RemoteEvent.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.