I was following a tutorial on how to make text appear when a part is touched and need some help. I am trying to make a typewriter effect also happen when the function is called.
Script in the part text will appear in:
local debounce = false
script.Parent.Touched:Connect(function (hit)
if not debounce then
debounce = true
if game.Players:GetPlayerFromCharacter(hit.Parent) then
game.ReplicatedStorage.ShowGui:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
end
wait(10)
debounce = false
end
end)
local textLabel = script.Parent:WaitForChild("TextLabel")
local function typeWrite(object,text)
for i = 1,#text,1 do
object.TextLabel = string.sub(text,1,i)
wait(0.2)
end
end
script in GUI:
game.ReplicatedStorage.ShowGui.OnClientEvent:Connect(function()
script.Parent.TextLabel.Visible = not script.Parent.TextLabel.Visible
end)
In the typewrite effect script, check the object.TextLabel to object.Text because Textlabel is not a vaild member of ScreenGui.TextLabel. Also try to combine the 2 localscripts and it will look like this.
local textLabel = script.Parent:WaitForChild("TextLabel")
local function typeWrite(object,text)
for i = 1,#text,1 do
object.Text = string.sub(text,1,i)
wait(0.2)
end
end
game.ReplicatedStorage.ShowGui.OnClientEvent:Connect(function()
script.Parent.TextLabel.Visible = not script.Parent.TextLabel.Visible
typeWrite(textLabel, " ") -- Anything
wait(5)
end)
local textLabel = script.Parent:WaitForChild("TextLabel")
local function typeWrite(object,text)
for i = 1,#text,1 do
object.Text = string.sub(text,1,i)
wait(0.05)
end
end
game.ReplicatedStorage.ShowGui.OnClientEvent:Connect(function()
script.Parent.TextLabel.Visible = not script.Parent.TextLabel.Visible
typeWrite(textLabel, "I will not go in the lake.") -- Anything
wait(5)
end)
@AidanPlaysYT_Real
Yeh, the code should work. Are you sure you textlabel’s visible property isn’t initially false. script.Parent.TextLabel.Visible = not script.Parent.TextLabel.Visible