Script does not work even though it should

-- Module Script for function
local TweenService = game:GetService("TweenService")
local SoundService = game:GetService("SoundService")

local module = {
	Appear_Function = function(Frame, AppearSound)
		AppearSound:Play()
		TweenService:Create(Frame, TweenInfo.new(AppearSound.TimeLength, Enum.EasingStyle.Linear), {BackgroundTransparency = 0}):Play()
		
		for i, v in Frame:GetDescendants() do
			if v:IsA("Frame") then
				TweenService:Create(v, TweenInfo.new(AppearSound.TimeLength, Enum.EasingStyle.Linear), {BackgroundTransparency = 0}):Play()
			elseif v:IsA("TextLabel") then
				TweenService:Create(v, TweenInfo.new(AppearSound.TimeLength, Enum.EasingStyle.Linear), {TextTransparency = 0}):Play()
			elseif v:IsA("UIStroke") then
				TweenService:Create(v, TweenInfo.new(AppearSound.TimeLength, Enum.EasingStyle.Linear), {Transparency = 0}):Play()
			elseif v:IsA("TextButton") then
				TweenService:Create(v, TweenInfo.new(AppearSound.TimeLength, Enum.EasingStyle.Linear), {TextTransparency = 0}):Play()
			end
		end
	end,
	
	Disappear_Function = function(Frame, DisappearSound)
		script.Parent:WaitForChild("ButtonSound").Enabled = true
		DisappearSound:Play()
		TweenService:Create(Frame, TweenInfo.new(DisappearSound.TimeLength, Enum.EasingStyle.Linear), {BackgroundTransparency = 1}):Play()
		
		for i, v in Frame:GetDescendants() do
			if v:IsA("Frame") then
				TweenService:Create(v, TweenInfo.new(DisappearSound.TimeLength, Enum.EasingStyle.Linear), {BackgroundTransparency = 1}):Play()
			elseif v:IsA("TextLabel") then
				TweenService:Create(v, TweenInfo.new(DisappearSound.TimeLength, Enum.EasingStyle.Linear), {TextTransparency = 1}):Play()
			elseif v:IsA("UIStroke") then
				TweenService:Create(v, TweenInfo.new(DisappearSound.TimeLength, Enum.EasingStyle.Linear), {Transparency = 1}):Play()
			elseif v:IsA("TextButton") then
				TweenService:Create(v, TweenInfo.new(DisappearSound.TimeLength, Enum.EasingStyle.Linear), {TextTransparency = 1}):Play()
			end
		end
	end,
}

return module
-- Local script for the exit button
local SoundService = game:GetService("SoundService")
local TweenService = game:GetService("TweenService")

local ExitButton = script.Parent
local SettingsFrame = ExitButton.Parent
local Menu = SettingsFrame.Parent.Parent

local Sounds = Menu:WaitForChild("Sounds")
local DisappearSound = Sounds:WaitForChild("DisappearSound")

local Buttons = Menu:WaitForChild("Buttons")
local Button_Scripts = Buttons:WaitForChild("Buton_Scripts")
local Button_Module = require(Button_Scripts:WaitForChild("Button_Module"))

local debounce = false

ExitButton.MouseButton1Click:Connect(function()
	if debounce == true then return end
	debounce = true

	Button_Scripts:WaitForChild("ButtonSound").Enabled = false
	Button_Module.Disappear_Function(SettingsFrame, DisappearSound)

	task.wait(2)
	debounce = false
end)

When I click the exit button to have a “fade effect” to fade out, it does NOT work. It only plays the sound and the code below it does NOT run even though it should and I’m pretty sure I’ve done everything correctly.

1 Like

That’s pretty strange. I think the issue might be with the way you’re defining the functions and the title of the table in the module script.

I’m not sure if this will work because I haven’t ever done it the way you’ve done it before, but maybe try writing the module and functions like this:

local Button_Module = {}

function Button_Module.Appear_Function(Frame, AppearSound)
    -- your code here
end

function Button_Module.Disappear_Function(Frame, DisappearSound)
    -- your code here
end

return Button_Module

Let me know if this helps. If not, I’ll try again haha.

I just checked roblox devforums. Sorry for being late. Anyways, I’m not sure if that will work though because I think you need it inside of the Module variable to be stored?

1 Like

Not sure if his way will fix things, but no what he did works fine syntax wise

1 Like

It is stored inside of the module, as the functions are created under it. Again, I don’t know if this will solve it since I’ve never really had a strange issue like this, nor have I used your initial method of writing the module, but I think it’s worth a shot?

local SoundService = game:GetService("SoundService")
local TweenService = game:GetService("TweenService")

local ExitButton = script.Parent
local SettingsFrame = ExitButton.Parent
local Menu = SettingsFrame.Parent.Parent

local Sounds = Menu:WaitForChild("Sounds")
local DisappearSound = Sounds:WaitForChild("DisappearSound")

local debounce = false

ExitButton.MouseButton1Click:Connect(function()
	if debounce == true then return end
	debounce = true
	
	DisappearSound:Play()
	TweenService:Create(SettingsFrame, TweenInfo.new(DisappearSound.TimeLength, Enum.EasingStyle.Linear), {BackgroundTransparency = 1}):Play()
	
	for i, v in SettingsFrame:GetDescendants() do
		if v:IsA("Frame") then
			TweenService:Create(v, TweenInfo.new(DisappearSound.TimeLength, Enum.EasingStyle.Linear), {BackgroundTransparency = 1}):Play()
		elseif v:IsA("TextLabel") then
			TweenService:Create(v, TweenInfo.new(DisappearSound.TimeLength, Enum.EasingStyle.Linear), {TextTransparency = 1}):Play()
		elseif v:IsA("UIStroke") then
			TweenService:Create(v, TweenInfo.new(DisappearSound.TimeLength, Enum.EasingStyle.Linear), {Transparency = 1}):Play()
		elseif v:IsA("TextButton") then
			TweenService:Create(v, TweenInfo.new(DisappearSound.TimeLength, Enum.EasingStyle.Linear), {BackgroundTransparency = 1}):Play()
			TweenService:Create(v, TweenInfo.new(DisappearSound.TimeLength, Enum.EasingStyle.Linear), {TextTransparency = 1}):Play()
		end
	end
	
	task.wait(2)
	debounce = false
end)

I attempted to rewrite it in case the module didn’t load fast enough but it still didn’t work. What the heck?

1 Like

I don’t see any issues with this code that it shouldn’t run. Is the LocalScript parented under the gui? Is everything placed where it should be so the script itself will actually run?

Just to make sure, even a statement such as print(“Button Clicked”) under the function doesn’t run?

I’d double check everything’s placement, let me know if anything still doesn’t work.

The local script is parented to the Exit Button and yes everything should be placed where it should be but let me check it again. I will add two print statements (One before the print sound and one after)


Okay this is insanely weird… None of the print statements printed even though the sound played?

local SoundService = game:GetService("SoundService")
local TweenService = game:GetService("TweenService")

local ExitButton = script.Parent
local SettingsFrame = ExitButton.Parent
local Menu = SettingsFrame.Parent.Parent

local Sounds = Menu:WaitForChild("Sounds")
local DisappearSound = Sounds:WaitForChild("DisappearSound")

local debounce = false

ExitButton.MouseButton1Click:Connect(function()
	if debounce == true then return end
	debounce = true
	
	print("Playing Sound...")
	DisappearSound:Play()
	print("Sound Played!")
	TweenService:Create(SettingsFrame, TweenInfo.new(DisappearSound.TimeLength, Enum.EasingStyle.Linear), {BackgroundTransparency = 1}):Play()
	
	for i, v in SettingsFrame:GetDescendants() do
		if v:IsA("Frame") then
			TweenService:Create(v, TweenInfo.new(DisappearSound.TimeLength, Enum.EasingStyle.Linear), {BackgroundTransparency = 1}):Play()
		elseif v:IsA("TextLabel") then
			TweenService:Create(v, TweenInfo.new(DisappearSound.TimeLength, Enum.EasingStyle.Linear), {TextTransparency = 1}):Play()
		elseif v:IsA("UIStroke") then
			TweenService:Create(v, TweenInfo.new(DisappearSound.TimeLength, Enum.EasingStyle.Linear), {Transparency = 1}):Play()
		elseif v:IsA("TextButton") then
			TweenService:Create(v, TweenInfo.new(DisappearSound.TimeLength, Enum.EasingStyle.Linear), {BackgroundTransparency = 1}):Play()
			TweenService:Create(v, TweenInfo.new(DisappearSound.TimeLength, Enum.EasingStyle.Linear), {TextTransparency = 1}):Play()
		end
	end
	
	task.wait(2)
	debounce = false
end)

Try commenting out all the code and printing something in there instead to see if it’s actually detecting the click or not.

local SoundService = game:GetService("SoundService")
local TweenService = game:GetService("TweenService")

local ExitButton = script.Parent
local SettingsFrame = ExitButton.Parent
local Menu = SettingsFrame.Parent.Parent

local Sounds = Menu:WaitForChild("Sounds")
local DisappearSound = Sounds:WaitForChild("DisappearSound")

local debounce = false

ExitButton.MouseButton1Click:Connect(function()
	if debounce == true then return end
	debounce = true
	
	print("hmmm")
	DisappearSound:Play()
	print("ok!")
	TweenService:Create(SettingsFrame, TweenInfo.new(DisappearSound.TimeLength, Enum.EasingStyle.Linear), {BackgroundTransparency = 1}):Play()
	
	--for i, v in SettingsFrame:GetDescendants() do
	--	if v:IsA("Frame") then
	--		TweenService:Create(v, TweenInfo.new(DisappearSound.TimeLength, Enum.EasingStyle.Linear), {BackgroundTransparency = 1}):Play()
	--	elseif v:IsA("TextLabel") then
	--		TweenService:Create(v, TweenInfo.new(DisappearSound.TimeLength, Enum.EasingStyle.Linear), {TextTransparency = 1}):Play()
	--	elseif v:IsA("UIStroke") then
	--		TweenService:Create(v, TweenInfo.new(DisappearSound.TimeLength, Enum.EasingStyle.Linear), {Transparency = 1}):Play()
	--	elseif v:IsA("TextButton") then
	--		TweenService:Create(v, TweenInfo.new(DisappearSound.TimeLength, Enum.EasingStyle.Linear), {BackgroundTransparency = 1}):Play()
	--		TweenService:Create(v, TweenInfo.new(DisappearSound.TimeLength, Enum.EasingStyle.Linear), {TextTransparency = 1}):Play()
	--	end
	--end
	
	task.wait(2)
	debounce = false
end)

None of the print statements printed… yet the sound played?

Interesting, is there any other script that interacts with button whenever its clicked?

And maybe try

ExitButton.Activated:Connect(function()
	--code
end
local SoundService = game:GetService("SoundService")
local TweenService = game:GetService("TweenService")

local ExitButton = script.Parent
local SettingsFrame = ExitButton.Parent
local Menu = SettingsFrame.Parent.Parent

local Sounds = Menu:WaitForChild("Sounds")
local DisappearSound = Sounds:WaitForChild("DisappearSound")

local debounce = false

ExitButton.Activated:Connect(function(input)
	if debounce == true then return end
	debounce = true
	
	print(input.KeyCode.Name)
	DisappearSound:Play()
	print("ok!")
	TweenService:Create(SettingsFrame, TweenInfo.new(DisappearSound.TimeLength, Enum.EasingStyle.Linear), {BackgroundTransparency = 1}):Play()
	
	--for i, v in SettingsFrame:GetDescendants() do
	--	if v:IsA("Frame") then
	--		TweenService:Create(v, TweenInfo.new(DisappearSound.TimeLength, Enum.EasingStyle.Linear), {BackgroundTransparency = 1}):Play()
	--	elseif v:IsA("TextLabel") then
	--		TweenService:Create(v, TweenInfo.new(DisappearSound.TimeLength, Enum.EasingStyle.Linear), {TextTransparency = 1}):Play()
	--	elseif v:IsA("UIStroke") then
	--		TweenService:Create(v, TweenInfo.new(DisappearSound.TimeLength, Enum.EasingStyle.Linear), {Transparency = 1}):Play()
	--	elseif v:IsA("TextButton") then
	--		TweenService:Create(v, TweenInfo.new(DisappearSound.TimeLength, Enum.EasingStyle.Linear), {BackgroundTransparency = 1}):Play()
	--		TweenService:Create(v, TweenInfo.new(DisappearSound.TimeLength, Enum.EasingStyle.Linear), {TextTransparency = 1}):Play()
	--	end
	--end
	
	task.wait(2)
	debounce = false
end)

Print statements didn’t even run only the sound…?

When I recreated your Gui setup it ran perfectly normal, I have no clue as to why it is not printing out
Could you send over the place, or the screen Gui in a separate place?

How do I send over the screen gui in a separate place?

Just copy the ScreenGui from your current place/game and paste it into a new place (might have to right click for the context menu which has more paste options) then send the new place over by dragging and dropping onto the reply box

I don’t want the place to be saved though. How do I delete it after it’s done?

You dont need to send the whole place you are working on just the screenGui that is causing the problem

I don’t know how to do this. Can you help me like explaining it? (First time trying to do it)