A few questions about scripting and gui

Hey guys, I’m back and I still don’t know how to script. As you know from the title, I have some questions about scripting and gui so here they are:

  1. Can I make animated text without scripting? By animated I mean it looks like it’s typing itself. A good example would be lots of those escape the ___ obbies.

  2. Why doesn’t this script work? It works when I take out the part that kicks players but I need it to kick the player when they click the button. Here’s the script:

local CloseButton = script.Parent.CloseButton
local WinnerGui = script.Parent

CloseButton.MouseButton1Click:Connect(function()
	WinnerGui.Enabled = false
	
CloseButton.MouseButton1Click:Connect(function()
		player:Kick(reason)
end)
end)

Typewriter effects have to be scripted. Use the MaxVisibleGrapheme property of the textlabel from 0 to the length of the string. Can tween that value or increment it in a loop.

The code snippet doesn’t work because you’re creating two connections to the same button – create two buttons, or add their code together (the kick and the gui enabled in one function)

2 Likes

You have two events and only one end.

Also, to get text to “animate like it’s typing itself”, you would need some scripting. But string.sub is our friend here.

local function animateText(text)
    for i = 0, #text do
        print(string.sub(text, 0, i))
        task.wait(1/20) -- 20 letters a second
    end
end
animateText("Example! :D Hi, how are you doing?")
1 Like

Ok, where do I put it in explorer? I tried putting it in a local script under the text lable and nothing happened.

You would have to alter the code slightly

local button = script.Parent
local exampleLabel = button.Parent:FindFirstChild("ExampleLabel")

local function animateText(textLabel, text)
    for i = 1, #text do
        textLabel.Text = string.sub(text, 0, i)
        task.wait(1/25)
    end
end

button.Activated:Connect(function()
    animateText(exampleLabel, "This is some example text to show xander how to implement this")
end)

Ya, I still can’t figure it out but that’s fine. The second one was the more important question.

Did I do anything else wrong in the second one? Adding an end didn’t work.

You’ve placed the end) in the wrong place

CloseButton.MouseButton1Click:Connect(function()
	WinnerGui.Enabled = false
end)

CloseButton.MouseButton1Click:Connect(function()
		player:Kick(reason)
end)

(remove the arrow)

1 Like

I removed the arrow and it still doesn’t work.

I gtg now though, I’ll keep trying later.

first, is the WinnerGui Disabled?

since

if it’s disabled then the close button wont show.

Wait, so your saying that the way I wrote it means that they have to click the button twice? Whoops. It doesn’t close though so that’s another problem that still happens.

This adjusted script should work:

local CloseButton = script.Parent.CloseButton
local WinnerGui = script.Parent

CloseButton.MouseButton1Click:Connect(function()
	WinnerGui.Enabled = false
        player:Kick(reason)
end)

There is no need to add two connected functions when the button is clicked as one can do it fine.

1 Like

Half works now so we’re making progress! It said “attempt to index nil with Kick”

It means the player variable is not defined. Have you ever created a player variable?

If not, add this at the top of your code:

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

No, I don’t even know what a player variable is.

It’s just referencing your player. I’ve updated my previous reply with some code you can use.

1 Like

It works! Thank you!

No problem! You can mark my answer as a solution by the way.

1 Like

I have a module for the typewriter effect! You can just put it into ReplicatedStorage.
Typerwriter - Module

1 Like