Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make aTypewriting TextLabel when touching part (One Time process)?

Asked by 2 years ago

Hi there!

Im wondering if I can have some help making a TextLabel pop up only once when touching a part.

Im only good at UI Making but not UI scripting. I wish I can get some help on this. Anyways, here's how my ScreenGUI is arranged:

PartGUI [ScreenGui]

TextFrame [FRAME]

TypewritingText [TextLabel]

Thank you for willing to answer my question :)

1 answer

Log in to vote
0
Answered by 2 years ago

This isn't really a site to ask for code but rather a site to ask help with any issues in your code, but nonetheless I will help you.

You can keep a nice local script in startergui in order to handle this code.

also a folder in replicatedstorage with a booleanvalue set to false that's how I like to do these sort of things but you can use your own detection method

It's actually a lot more simple than it seems.

local textGui = script.Parent:FindFirstChild("ScreenGui"):FindFirstChild("Frame").TextLabel -- stores the textlabel for the typewrite effect

local bool = game:GetService("ReplicatedStorage"):WaitForChild("bools"):FindFirstChild("touchBool") -- stores the boolean value stored inside a folder in replicatedstorage

local function typewrite(object,text,speed)
    for i = 1,#text,1 do

        object.Text = string.sub(text,1,i)
        wait(speed)
    end
end
-- the function for the typewriting effect, the keywords inside the paranthesis are variables that you can store when calling the function

-- example being typewrite(textGui,"hello world",0.035) it targets the textlabel, with the text saying 'hello world' and it takes .035 seconds for each letter to be typed

bool.Changed:Connect(function() -- detects if the boolean value changes, if it does then it runs code inside this block
    typewrite(textGui,"hello world",0.035) -- runs the function
    wait(2.5)
    textGui.Text = " " -- sets the text back to nothing after the dialogue is finished
end)

in order to get the boolean value to change we will need to detect if a player touches a part. we use a server script for that in serverscriptservice

local part = game.Workspace.touchTrigger -- stores the part that you need to touch change this to wherever your part is

part.Touched:Connect(function(touchPart) -- detects if something touches the part
    local humanoid = touchPart.Parent:FindFirstChildWhichIsA("Humanoid")
    if humanoid then -- detects if its a player
        game:GetService("ReplicatedStorage"):WaitForChild("bools"):FindFirstChild("touchBool").Value = true -- sets the bool value to true
    end
end)

Sorry if this doesn't explain much I had to rush this.

If you have any more questions you can look through the dev wiki to learn how lua works and how it works with roblox and such https://developer.roblox.com/en-us/

Ad

Answer this question