Textbutton not enabling Script

Hey everyone! So what I am trying to achieve is my game has a loading screen, and in this loading screen there is a type-writer effect which is basically a textlabel with a script in it. The problem is, the script is timed so you can’t spend more than a minute in the main menu without the type-writer sound going off in the background without the actual text itself. So what I’ve done is disable that script inside that textlabel and when you click the button which opens the loading screen, that script is supposed to be enabled not disabled.

local Textlabel = script.Parent.Parent.Parent.FFrame.TextLabel
local Script = script.Parent.Parent.Parent.FFrame.TextLabel.Script

script.Parent.MouseButton1Click:Connect(function()		
			if Script.ClassName == "Script" and Script.Name == "Script" then
				Script.Disabled = false
	end
end)

Kind of confused, you want to disable all the scripts inside the button?

Nevermind, I understand it. Try this (haven’t tested, if it doesn’t work let me know)

local TextLabel = script.Parent.Parent.Parent.FFrame.TextLabel

script.Parent.MouseButton1Click:Connect(function()		
	TextLabel.Script.Disabled = false
end)

Hey, @BuildermanonYt. If you want to check something’s type, className, etc. an easy method for this would be like the following:

Could be:

if Script:IsA("Script") then
-- code
end

BUT
All interface is Local so I would always use a LocalScript on the client-side/and for UI handling. :slight_smile:

1 Like

I tried the script you sent me and it unfortunately didn’t solve the issue, By the way, the code inside the disabled script inside TextLabel is this:

local TextLabel = script.Parent
local Text

function SoundEffect()
    local Sound = Instance.new("Sound", workspace)
Sound.Name = "TextSound"
Sound.SoundId = "http://www.roblox.com/asset/?id=3333976425"
Sound.PlaybackSpeed = 1
Sound.Volume = 1
Sound:Play()
coroutine.resume(coroutine.create(function()
wait(1)
Sound:Destroy()
end))
end

function setText(word)
Text = word
for i = 1, #Text do
TextLabel.Text = string.sub(Text, 1, i)
SoundEffect()
TextLabel.TextColor3 = Color3.fromRGB(255,255,255)
wait(0.04)
end
end

wait(10)
setText("Hi there")
wait(2)
setText("You are a S.E.C.U.R.O guard at this hotel")
wait(3)
setText("Your job is to fix anything out of the ordinary")
wait(3)
setText("Make sure to report issues in the S.E.C.U.R.O app")
wait(3)
setText("You will be provided with cameras, and a stock PC")
wait(3)
setText("Don't die.")

I gotcha! Try this:

local TextLabel = script.Parent
local Text

function SoundEffect()
    local Sound = Instance.new("Sound", workspace)
	Sound.Name = "TextSound"
	Sound.SoundId = "http://www.roblox.com/asset/?id=3333976425"
	Sound.PlaybackSpeed = 1
	Sound.Volume = 1
	Sound.Looped = true
	return Sound
end

function setText(word)
	Text = word
	local Sound = SoundEffect()
	Sound:Play()
	
	for i = 1, #Text do
		TextLabel.Text = string.sub(Text, 1, i)
		TextLabel.TextColor3 = Color3.fromRGB(255,255,255)
		wait(0.04)
	end
	
	Sound:Stop()
	Sound:Destroy() -- get rid of the sound effect
end

wait(10)
setText("Hi there")
wait(2)
setText("You are a S.E.C.U.R.O guard at this hotel")
wait(3)
setText("Your job is to fix anything out of the ordinary")
wait(3)
setText("Make sure to report issues in the S.E.C.U.R.O app")
wait(3)
setText("You will be provided with cameras, and a stock PC")
wait(3)
setText("Don't die.")

So what I did was:
Re-organize the SoundEffects() function (which now uses Sound.Looped = true).
Then after the word is fully typed out, the sound will :Stop() and then be removed.

1 Like

Hope this helped, if so make sure to mark the answer! If not, let me know if I can help more. :slight_smile:

1 Like

I’m pretty sure that’s because you’re doing this on a local script

2 Likes

Maybe instead of using a server script and disabling and enabling it replace it with a local script, this is because the client cant see server scripts! If you do that it should work just fine!

1 Like

or you can send remote events to do client to server changes

1 Like

Thank you for the organized script, and I am going to try and make the script a local script and see if it works.

What you should do is fire a remote event and on the server enable the script.

1 Like

I changed it so that instead of server script, it’s a local script, and when I defined it in the textbutton local script, it seems to function correctly. Thanks!