Ad
Log in to vote
0

Why does this textlabel typewrite script give no errors?

Asked by 2 days ago
local part = workspace.Button
local player = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
local proximityprompt = workspace.Button.ProximityPrompt

local textlabel = game.StarterGui.ConversationGui.TextHere
local name = game.StarterGui.ConversationGui.Name
local dialog = game.StarterGui.ConversationGui

local function typewrite(object,text)
    for i = 1,#text,1 do
        object.Text = string.sub(text,1,i)
        wait(0.025)
    end
end

proximityprompt.TriggerEnded:Connect(function()
    if dialog.Enabled == true then
        return
    elseif dialog.Enabled == false then
        proximityprompt.Enabled = false
        wait(0.2)
        dialog.Enabled = true
        typewrite(textlabel,"HEY! This is private property! Don't make-")
        wait(2)
        textlabel.TextXAlignment = 2
        textlabel.TextYAlignment = 1
        typewrite(textlabel,"Wait...")
        wait(2)
        typewrite(textlabel,"You- You're HIM!")
        wait(2)
        textlabel.TextXAlignment = 0
        textlabel.TextYAlignment = 0
        typewrite(textlabel,"I'm sorry, that wasn't very nice of me. I'm sure you're a amazing human being!")
        wait(3)
        textlabel.TextXAlignment = 2
        textlabel.TextYAlignment = 1
        typewrite(textlabel,"M-My name is Xanathaniel.")
        typewrite(name,"Xanathaniel")
        wait(2)
        textlabel.TextXAlignment = 0
        textlabel.TextYAlignment = 0
        typewrite(textlabel,"Come back if you ever need help with anything!")
        wait(2)
        dialog.Enabled = false
        wait(0.2)
        proximityprompt.Enabled = true
    end
end)

This is the script I'm currently trying to use for my dialog. The problem is, I get no errors, but it doesn't work so I have no idea where to even start to fix it.

I hope someone knows how I could fix it.

2 answers

Log in to vote
1
Answered by 2 days ago
Edited 2 days ago

As mentioned before, this is because you are making changes to the StarterGui, not the PlayerGui.

This is because StarterGui is where you store your games' gui. When the player's character is loaded, ROBLOX automatically clones all of StarterGui's contents to the PlayerGui. These are the GUIs which are displayed to each individual player.

I should also mention your typewriter script. It's pretty decent, but if you want ROBLOX provides a typewriter module which features translations, which I will paste below if you want to have a look at it.

local SOURCE_LOCALE = "en"

local LocalizationService = game:GetService("LocalizationService")
local Players = game:GetService("Players")

local player = Players.LocalPlayer

local translator = nil
pcall(function()
    translator = LocalizationService:GetTranslatorForPlayerAsync(player)
end)
if not translator then
    pcall(function()
        translator = LocalizationService:GetTranslatorForLocaleAsync(SOURCE_LOCALE)
    end)
end

local TypeWriter = {}

local defaultConfigurations = {
    delayTime = 0.2,
    extraDelayOnSpace = true
}

function TypeWriter.configure(configurations)
    for key, value in pairs(defaultConfigurations) do
        local newValue = configurations[key]
        if newValue ~= nil then
            defaultConfigurations[key] = newValue
        else
            warn(key .. " is not a valid configuration for TypeWriter module")
        end
    end
end

function TypeWriter.typeWrite(guiObject, text)
    guiObject.AutoLocalize = false
    guiObject.Text = ""
    local displayText = text
    if translator then
        displayText = translator:Translate(guiObject, text)
    end
    for first, last in utf8.graphemes(displayText) do
        local grapheme = string.sub(displayText, first, last)
        guiObject.Text = guiObject.Text .. grapheme
        if defaultConfigurations.extraDelayOnSpace and grapheme == " " then
            wait(defaultConfigurations.delayTime)
        end
        wait(defaultConfigurations.delayTime)
    end
end

return TypeWriter

Anyway, use whichever you prefer. The one above does handle translations though, which makes your game more accessible.

As for your script, there is another thing wrong with it. Now we've sorted the playerGui issue, let's talk about line 6

local name = game.StarterGui.ConversationGui.Name

This would store the variable, literally as

local name = "ConversationGui"

Why?

Sometimes the Name of an object is the same as that of a property of its Parent. When using the dot operator, properties take precedence over children if they share a name.

Therefore to fix that, we use FindFirstChild() or any similar method.

local part = workspace.Button
local player = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
local proximityprompt = workspace.Button.ProximityPrompt

local playerui = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui") 
-- WaitForChild used as some things load slower than the scripts through the client.

local dialog = playerui.ConversationGui
local textlabel = dialog.TextHere
local name = dialog:FindFirstChild("Name")
-- because "Name" is a property, it would have priority when indexed. Therefore we use 
-- :FindFirstChild() or any similar method to specify we are searching for a child within a parent.

local function typewrite(object,text)
    for i = 1,#text,1 do
        object.Text = string.sub(text,1,i)
        wait(0.025)
    end
end

proximityprompt.TriggerEnded:Connect(function()
    if dialog.Enabled == true then
        return
    elseif dialog.Enabled == false then
        proximityprompt.Enabled = false
        wait(0.2)
        dialog.Enabled = true
        typewrite(textlabel,"HEY! This is private property! Don't make-")
        wait(2)
        textlabel.TextXAlignment = 2
        textlabel.TextYAlignment = 1
        typewrite(textlabel,"Wait...")
        wait(2)
        typewrite(textlabel,"You- You're HIM!")
        wait(2)
        textlabel.TextXAlignment = 0
        textlabel.TextYAlignment = 0
        typewrite(textlabel,"I'm sorry, that wasn't very nice of me. I'm sure you're a amazing human being!")
        wait(3)
        textlabel.TextXAlignment = 2
        textlabel.TextYAlignment = 1
        typewrite(textlabel,"M-My name is Xanathaniel.")
        typewrite(name,"Xanathaniel")
        wait(2)
        textlabel.TextXAlignment = 0
        textlabel.TextYAlignment = 0
        typewrite(textlabel,"Come back if you ever need help with anything!")
        wait(2)
        dialog.Enabled = false
        wait(0.2)
        proximityprompt.Enabled = true
    end
end)
0
Much more detailed than mine. radiant_Light203 510 — 2d
0
I thought about everything you said and fixed my script, but the entire ConversationGui.Enabled does nothing even thought it's in the script? Also it gives no errors Idk if that's good or bad. LimitedVxrsion 3 — 2d
0
No errors usually means there is nothing wrong with it, it's simply just not doing what you intended it to but correctly. Not sure what could be wrong rodrigo455 558 — 2d
Ad
Log in to vote
0
Answered by 2 days ago

Your dialogue variable should point to the player's GUI not the game's!

It's local dialogue = player.PlayerGUI.ConversationGui. Otherwise you're editing the starter GUI which everyone will be getting.

0
Doesn't a local script automaticly edit a player's GUI instead of everyone's GUI? LimitedVxrsion 3 — 2d
0
Yes, but you have to edit the player's Gui, StarterGui, it is the Gui that is cloned by the server to the player when the player enters the server or dies. genilsonotavio 114 — 2d

Answer this question