How do I make text inside of a frame appear? Roblox

Hey!
I was trying my best to make a DialogueGui but it dosen’t seem to work! ;-;

i just want to make the gui appear when “PortalShakeActivator” is touched by a player.

Here is the code :-

local DialougePart1 = script.Parent.PortalShakeActivator
text1 = "Waiting for players to load..."


for i = 1,#text1 do
	script.Parent.Text = string.sub(text1,1,i)
	wait(0.05) -- the time each words get typed in
end

I think i explained it a little wrong… i want the text to appear when “PortalShakeActivator” is Touched by a player

image

local DialougePart1 = script.Parent.PortalShakeActivator
text1 = "Waiting for players to load..."


for i = 1,#text1 do
	script.Parent.Text = string.sub(text1,1,i)
	wait(0.05) -- the time each words get typed in
end

Send a picture of the UI, so I can see how the UI looks like. Could be a text scale issue.

Here is the ui

And thanks for replying!

you didn’t include the touch detection connection in the code :pensive:

lmao not sure if this has anything to do with the problem

anyways

try smth like this
assuming that PortalShakeActivator is a BasePart and all your paths are correct:

local DialoguePart1 = script.Parent:WaitForChild("PortalShakeActivator")
local dialogueGui = script.Parent:WaitForChild("DialogueGui"):WaitForChild("DialogueFrame"):WaitForChild("TextLabel")
local text1 = "Waiting for players to load..."

local function typeText(guiElement, text)
    for i = 1, #text do
        guiElement.Text = string.sub(text, 1, i)
        task.wait(0.05) -- the time each character appears
    end
end

local function onTouched(player)
    if player and player:IsA("Player") then
        typeText(dialogueGui, text1)
    end
end

DialoguePart1.Touched:Connect(onTouched)

i didn’t just add the connection but a couple of other things:

  • i replaced wait(0.05) with task.wait(0.05) because wait is deprecated
  • i referenced paths with WaitForChild() just incase they didnt load

now, let’s say i’m wrong and PortalShakeActivator isn’t a BasePart and was a TextButton or an ImageButton. here’s what you would do:

  • all you need to do is change the last line
  • the last line is DialoguePart1.Touched:Connect(onTouched)
  • you need to replace the Touched with Activated
  • that means that it’d become DialoguePart1.Activated:Connect(onTouched)

now this is very very important:
your dialogue script is a ServerScript (for simplification, the icon in explorer is gray). it needs to be a LocalScript instead of a ServerScript so that it functions properly and doesn’t affect other players in the game (for simplification, the LocalScript icon should be blue and it should have a monitor-looking section on the bottom right of the icon).

i might’ve forgotten some things but wtv
mark me as solution if i solved your problem

2 Likes

Yooo man thankss!!! let me try the script and see if it works

I am sorry, but this still isn’t working… But thanks for trying to help me :smile:

image_2024-04-03_082404498

this is the portal shake activator. the folder is inside workspace btw. and the script which you gave me is inside the “DialougeActivator”

Yo! soo, i have kinda fixed the thing…

I made the gui appear when i touch the part.

script :-

local TouchPart = game.Workspace.DialougeParts:WaitForChild("PortalShakeActivator") -- Change Part to whatever your part is called which a player will need to touch
local gui = script.Parent
gui.TextLabel.TextTransparency = 1
TouchPart.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and hit.Parent == game.Players.LocalPlayer.Character then
		gui.TextLabel.TextTransparency = 1
		task.wait(0.3)
		gui.TextLabel.TextTransparency = 0.90
		task.wait(0.3)
		gui.TextLabel.TextTransparency = 0.70
		task.wait(0.3)
		gui.TextLabel.TextTransparency = 0.20
		task.wait(0.3)
		print("Gui opened")
	end
end)

Okay, snaz, you’ve got it working, but I would like to introduce you to a fundamental principal that makes us stop repeating ourselves while we code, this is useful as it:

  • Saves us time when writing code

  • Makes it easier for other programmers to read.

We should also make sure that our code is as efficient as possible, this means we shouldn’t have any lines of code we don’t need.


This is my attempt at tidying up your code, I have added a list of comments below, just to let you know what I’ve changed:

local TweenService =game:GetService("TweenService")
local TouchPart = game.Workspace.DialougeParts:WaitForChild("PortalShakeActivator")
local gui = script.Parent

local Debounce = false 

TouchPart.Touched:Connect(function(hit)
	if hit.Parent.Name == game.Players.LocalPlayer.Name and Debounce == false then 
		TweenService:Create(gui.TextLabel, TweenInfo.new(1), { TextTransparency = 0 }):Play() 
		print("Gui opened")
		Debounce = true
	end
end)

What I changed:

  • Import the TweenService, this allows us to interpolate properties of instances (this allows to create easy animations).

  • I add something called a debounce, in short roblox will continuously fired the Touched event, even if the user is touching the part and not moving, which is not good as it will make the code execute too many times.

    • To counter this we add a Debounce variable, meaning as soon as we touch it, we set this variables value to True and this prevents the code which makes the TextLabel Text visible can’t run again.
  • I also removed the TextTransparency=1 line here as it is useless, just text TextTransparency to be inside of Roblox Studio.

  • Before you were checking two times, if their was a player & if the player had a specific name, I made this one check, I also check to make sure the value of the Debounce variable is false.

  • I then create a Tween, which I set to take 1 second, you can change the amount of seconds by ammending that line.

  • I then play the tween I’ve created.

  • I print “Gui Opened”, as you had that before.

  • Then I set debounce to be true so that the code can’t run again.

Hope this helps! :slight_smile:

1 Like

was literally writing this but just saw you beat me to it lol


anyways some more stuff i wanted to point out—smth i js caught onto

  1. referencing LocalPlayer: game.Players.LocalPlayer is only valid in LocalScripts
  2. UI manipulation: UI elements should be manipulated from the client side, not the server side
  3. @Noah beat me to this so nvm lmao

so i would resolve by:

  • move UI manipulation to LocalScript: the script that manipulates the UI should be a LocalScript so it can properly access LocalPlayer and modify the player’s UI without problems.

  • server to client communication—if the intention is to have a server-side event (touching a part) trigger client-side behavior (changing UI transparency), you should use RemoteEvents. the ServerScript can fire a RemoteEvent when the part is touched, and a LocalScript listening to this event can then change the UI transparency/fade the UI.

ok this is how i would structure it with RemoteEvents:

this is the ServerScript:

local TouchPart = game.Workspace.DialougeParts:WaitForChild("PortalShakeActivator")
local remoteEvent = game.ReplicatedStorage:WaitForChild("YourRemoteEventName") -- pls make sure you have a RemoteEvent under ReplicatedStorage and adjust the path

TouchPart.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        remoteEvent:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent)) -- this line fires the event for the player who touched the part
    end
end)

this is the LocalScript (child of the UI):

local remoteEvent = game.ReplicatedStorage:WaitForChild("YourRemoteEventName")
local gui = script.Parent

remoteEvent.OnClientEvent:Connect(function()
--do what @Noah mentioned about `TweenService`
end)

ignore the deleted post above, sent it on accident while typing

Can’t all of this be chucked in a local script without the need for server - client communication?

nooo i js took a closer look and read your paths and realized (i js skimmed through it)—i was under the assumption that the part was using script.Parent and the LocalScript was in Workspace, and LocalScripts cannot be run in Workspace (assuming you didn’t have Client as the RunContext in a ServerScript)

i flipped it in the version i just sent and even if that was the case my silly mind wouldn’t have thought of moving it and replacing the paths like you did. but yeah that would work and there’s no need for anything i said, ignore that—i misread your code and that misled me :sweat_smile:

one last thing just for polishing though, Touched and TouchEnded by Roblox is very unreliable and inaccurate. i think using the ZonePlus module by @ForeverHD is a better option: ZonePlus v3.2.0 | Construct dynamic zones and effectively determine players and parts within their boundaries - Community Resources - Developer Forum | Roblox

this is unnecessary though

but it’d be more accurate and work as an alternative to fixing the unreliability of Touched you discussed

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