Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

TypeWriter - How do I make it so that if a part is touched, it types?

Hello, I'm working on a game with TypeWriter and I want to make it so that if a Part is touched, the TypeWriter starts to type. Here is the code in the part.

script.Parent.Touched:Connect(function()
	workspace.ScreenGui.Frame.LocalScript
		= text "Good, now let's go to the next part."
for i = 1, #text do
	script.Parent.TextLabel.Text = string.sub(text, 1, i)
	wait(0.07)
	
end
 
end)

Here is the TypeWriter script:

local text = "Hello and welcome to this quiz, I'll be testing you if you're smart."
for i = 1, #text do
	script.Parent.TextLabel.Text = string.sub(text, 1, i)
	wait(0.07)
	
end
wait(3)
local text = "Let's see if you can get out of this box..."
for i = 1, #text do
	script.Parent.TextLabel.Text = string.sub(text, 1, i)
	wait(0.07)
	
end

So I want it to type "Good, now let's go to the next part." after the player touches the Part. Also, I'm very bad at scripting, so I don't know how to explain much about scripts.

When I touched the part, it doesn't work, it just stays on the text "Let's see if you can get out of this box..."

1 answer

✓ Accepted answer
-- Client Script
-- Place into a TextLabel

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer

local TextLabel = script.Parent -- Our TextLabel 

local PartToTouch = workspace.Part -- Our Part to touch
local DebounceCheck = true -- Our debounce

local ListOfSentences = { -- Put a sentence of yours here.
  'Hello, want to eat burger?';
  'Was it delicious?';
  'Good to know!'
}

PartToTouch.Touched:Connect(function(Hit) -- Connection when parts touched & touched arguement
 local Player = Players:GetPlayerFromCharacter(Hit.Parent) -- Our Player
 if Player == LocalPlayer and DebounceCheck then -- Checking if it's the Client player we need.
		DebounceCheck = false
		for _,Strings in pairs(ListOfSentences) do -- Iterating through our lists of sentences table.
		  for Index = 1, #Strings do -- Beginning our 'type writer effect'
			  TextLabel.Text = (Strings):sub(1, Index)
              wait(.07)
           end
		   wait(2) -- Delay between changing sentences
		end
		DebounceCheck = true -- Enabling it back so it can be touched again.
		TextLabel.Text = '' -- Clearing our text to reset. You can remove this line if you don't want it.
	end
end)

Hope this has helped you, please learn from this code i've provided you. Have a wonderful day and continue with your passion in developing.

3 comments

0

Thank you, it works :D

0

This is bad code you should put a local function with the text your giving him a memory leak basically wth!

0

@fistter1 by looking at your profile and your questions it's obvious you don't know what you're on about.

This discussion is preserved as it was. New answers, comments, and votes are closed.