Search code examples
luaroblox

Roblox Lua Developpement


I am trying to make a Roblox game, but when I script in Lua nothing happened when I touched the door.

The StarterGui for TextLabel:

game.Workspace.text:GetPropertyChangedSignal("Value"):Connect:(function())
    local text = script.Parent
    if game.Workspace.text.Value == 1 then
        script.Parent.Parent.Visible = true
        text.Text = "W"
        wait (.05)    
        text.Text = "We"
        wait (.05)   
        text.Text = "Wel"
        wait (.05)   
        text.Text = "Welc"
        wait (.05)   
        text.Text = "Welco"
        wait (.05)   
        text.Text = "Welcom"
        wait (.05)   
        text.Text = "Welcome"
        wait (.05)   
        text.Text = "Welcome !"
        wait (.05)
        wait (3)
        text.Text = "C"
        wait (.05)    
        text.Text = "Co"
        wait (.05)   
        text.Text = "Come"
        wait (.05)   
        text.Text = "Come I"
        wait (.05)   
        text.Text = "Come In "
        wait (.05)   
        text.Text = "Come In !"
        wait (.05)   
        wait (3)
        script.Parent.Parent.Visible = false       
    end 
end)

The code for the door:

script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
    game.Workspace.text.Value = 1
    end
end)

Solution

  • Well, there are some problems here but I am willing to help you! I'll show you how to properly animate text and efficiently!

    First off you probably tried scripting the UI from a Server-Side script. When working with Graphical User Interface on Roblox, make sure you are coding Guis with a LocalScript so it is Client-Side. If you want to change UI for all Clients, you would use something called A RemoteEvent more on that later

    I will provide the open source code and I will explain (if you want)

    Here are some things you will need:

    • A "RemoteEvent" inside of ReplicatedStorage (Name it: DoorEvent)
    • A "ScreenGui" inside of StarterGui
    • A TextLabel within the ScreenGui (customize to your liking)

    Now, insert a regular script inside of ServerScriptService ("Just for exploit prevention)

    Here is the door script:

    local ReplicatedStorage = game:GetService("ReplicatedStorage")
    local DoorEvent = ReplicatedStorage:WaitForChild("DoorEvent")
    local door = workspace:FindFirstChild("NAME OF DOOR HERE")
    
    door.Touched:Connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") ~= nil then
            local hum = hit.Parent:FindFirstChild("Humanoid")
            if hum then
                local player = game:GetService("Players"):FindFirstChild(hit.Parent.Name)
                if plr then
                    DoorEvent:FireClient(plr)
                end
            end
        end
    end)
    

    Basically this just uses a touched event to fire a RemoteEvent, we use it because of a Property called FilteringEnabled (exploiter purposes)

    Now proceed to insert a LocalScript inside of the TextLabel and insert this code. (DONT WORRY IT MAY LOOK CONFUSING JUST ASK FOR CLARIFICATION IF YOU WANT)

    Code:

    local ReplicatedStorage = game:GetService("ReplicatedStorage")
    local DoorEvent = ReplicatedStorage:WaitForChild("DoorEvent")
    local TextLabel = script.Parent
    local text
    
    local function animateText(word)
        text = word
        for char = 1, #text do
            TextLabel.Text = string.sub(text,1,char)
            wait(.05)
        end
    end
    
    animateText("This is an example sentence, put whatever you want here as a string.")
    wait(2.5)
    animateText("You can repeat this as many times as you wish")
    
    --If you want to get rid of the text when it's done you can either tween it or simply toggle the visibility)