Hello,
I’m trying to make a horror game on Roblox and I discovered how to make a dialogue typewrite effect and a menu for the game, I want when you press the play button to start the dialogue. I tried this script below but it doesn’t work even though I don’t have any error.
local playbtn = game:GetService("StarterGui").ScreenGui1.BG.PlayButton
playbtn.MouseButton1Click:Connect(function()
local function typewrite(object,text,length)
for i = 1,#text,1 do
object.Text = string.sub(text,1,i)
wait(length)
end
end
typewrite(script.Parent, "subscribe bro", 0.05)
end)
This will be the thousandth time I tell someone to DESCRIBE their issue and don’t just say “it doesn’t work”. That is not enough. We are not magicians, most of the time we cannot instantly pinpoint your issue and solve it in a heartbeat.
Also, the typewriter effect you’re trying to have can be simplified with the .MaxVisibleGraphemes property.
I’m sorry for not giving more details, I quit Roblox because I got scammed and recently I started creating some games and I noticed that many things have changed on the DevForum and yeah…
local playbtn = game:GetService("StarterGui").ScreenGui1.BG.PlayButton
playbtn.MouseButton1Click:Connect(function()
local function typewrite(object,text,length)
for i = 1,#text,1 do
object.Text = string.sub(text,1,i)
wait(#text / length)
end
end
typewrite(script.Parent, "subscribe bro", 0.05)
end)
This is a pretty common mistake people make. StarterGui is what’s being replicated to players when they join the game. It’s not the player’s actual GUI, so editing it won’t do anything, especially from the client. You’re supposed to use LocalPlayer.PlayerGui to access it.
I’ve completely changed the script, try this:
local lp = game:GetService("Players").LocalPlayer
local playbtn = lp.PlayerGui:WaitForChild("ScreenGui1"):WaitForChild("BG"):WaitForChild("PlayButton")
local function typewrite(object, text: string, delay: number)
object.Text = text
local i: number = 0
for _ in utf8.graphemes(text) do
i += 1
object.MaxVisibleGraphemes = i
task.wait(delay)
end
end
playbtn.MouseButton1Click:Connect(function()
typewrite(playbtn, 'subscribe bro', 0.05)
end)
Yes, I looked over what he sent me but I don’t understand anything because I’ve never coded on Roblox in my life and it’s the first time I try something like this. Besides, I’m not American and I don’t understand English that well.
You can’t get the PlayerGui with just a normal server script, you gotta get the player somehow. Just move this script in this LocalScript
or if you really want it with a server script do this
local playbtn = script.Parent.Parent.Parent.ScreenGui1.BG.PlayButton
local function typewrite(object,text,length)
for i = 1,#text,1 do
object.Text = string.sub(text,1,i)
wait(length)
end
end
playbtn.MouseButton1Click:Connect(function()
typewrite(script.Parent, "subscribe bro", 0.05)
end)
So I need to add the Script that VERON gave me into that local script? Like this?
--// Variables
local cam = workspace.CurrentCamera
local camPart = workspace["MenuCamera"]
local mouse = game:GetService("Players").LocalPlayer:GetMouse()
local PlayBTN = script.Parent.BG.PlayButton
local scary = game.Workspace.scaryplay
--// Set cam
repeat
wait()
cam.CameraType = Enum.CameraType.Scriptable
until
cam.CameraType == Enum.CameraType.Scriptable
--// Move cam
local maxTilt = 10
game:GetService("RunService").RenderStepped:Connect(function()
cam.CFrame = camPart.CFrame * CFrame.Angles(
math.rad((((mouse.Y - mouse.ViewSizeY / 2) / mouse.ViewSizeY)) * -maxTilt),
math.rad((((mouse.X - mouse.ViewSizeX / 2) / mouse.ViewSizeX)) * -maxTilt),
0
)
end)
function Play()
cam.CameraType = Enum.CameraType.Custom
script.Parent:Destroy()
scary:Play()
local lp = game:GetService("Players").LocalPlayer
local playbtn = lp.PlayerGui:WaitForChild("ScreenGui1"):WaitForChild("BG"):WaitForChild("PlayButton")
local function typewrite(object, text: string, delay: number)
object.Text = text
local i: number = 0
for _ in utf8.graphemes(text) do
i += 1
object.MaxVisibleGraphemes = i
task.wait(delay)
end
end
playbtn.MouseButton1Click:Connect(function()
typewrite(playbtn, 'subscribe bro', 0.05)
end)
end
PlayBTN.MouseButton1Click:Connect(Play)