ClickDetector won't work

Entire Script:

local Lib = workspace.Multiplayer.GetMapVals:Invoke() --Has: Map, Script, Button, btnFuncs
Lib.Button:connect(function(p, bNo) if Lib.btnFuncs[bNo] then Lib.btnFuncs[bNo](bNo, p) end end)

local DisableChoose = false
local ExternalScriptsEnabled
local FE2CM
local ScriptsVar = "Inactive"

local Lobby = game.Workspace.Lobby
local LobbyDetails = Lobby:WaitForChild("Detail")
local LobbyWaters = Lobby.Waters
local LobbyChoices = script.Parent.LobbyChoices
local Alert = game:WaitForChild("ReplicatedStorage").Remote.Alert

local Lobby1 = script.Parent.Lobby1
local Lobby2 = script.Parent.Lobby2
local Lobby3 = script.Parent.Lobby3
local Lobby4 = script.Parent.Lobby4

if script.Parent:FindFirstChild("ExternalScript") then
	ExternalScriptsEnabled = true
else
	ExternalScriptsEnabled = false
	Alert:FireAllClients("Make sure to turn on Load All Scripts when inserting lobbies with a warning symbol! ⚠", Color3.fromRGB(255, 0, 0))
end

if Lobby:FindFirstChild("_NonChina"):FindFirstChild("SocialMedia") then
	FE2CM = "Legacy"
	Alert:FireAllClients("!! WARNING: THIS MAP WAS NOT BUILT FOR FE2CM LEGACY AND MAY BREAK SOME ASPECTS OF ANY LOBBIES OR EVEN MAPS LOADED !!", Color3.fromRGB(255, 0, 0))
else
	FE2CM = "Auto"
end

Alert:FireAllClients("!! DO NOT LOAD THE FOURTH LOBBY RIGHT NOW AS IT IS CURRENTLY BROKEN !!", Color3.fromRGB(255, 0, 0))

Lobby.PrimaryPart = Lobby:WaitForChild("RescueMonitor"):WaitForChild("TV")
Lobby1.PrimaryPart = Lobby1:WaitForChild("RescueMonitor"):WaitForChild("TV")
Lobby2.PrimaryPart = Lobby2:WaitForChild("RescueMonitor"):WaitForChild("TV")
Lobby3.PrimaryPart = Lobby3:WaitForChild("RescueMonitor"):WaitForChild("TV")
Lobby4.PrimaryPart = Lobby4.Detail:WaitForChild("RescueMonitor"):WaitForChild("TV")

--[[ DEFAULT CHANGE PART COLOR SCRIPT
if part.Color == Color3.fromRGB() then
	part.Color = Color3.fromRGB()
end
]]

local HandleScripts = coroutine.wrap(function()
	
	local ScriptsFolder = Instance.new("Folder")
	ScriptsFolder.Parent = game.ReplicatedStorage
	
	local Flicker = Lobby.Block.Flicker
	local MapImgs1 = Lobby.MapImgs.PicFrame.Contents.Script
	--local GhostlyAnim = Lobby._NonChina.Ghostlyx_x.Animate
	--local GhostlyScript = Lobby._NonChina.Ghostlyx_x.Script
	local PlayHere = Lobby.PlayHere.SurfaceGui.Script
	local GameInfo = Lobby.GameInfo.SurfaceGui.Script
	local MapImgs2 = Lobby.MapImgs.PicFrame.Contents.Script
	local CCTV = Lobby.Detail.RescueMonitor.TV.SurfaceGui.Frame.CCTV.Static.Script
	local Leaderboard = Lobby.DonationLeaderboard.LeaderUI.DonationLeaderboard
	
	Flicker.Parent = ScriptsFolder
	MapImgs1.Parent = ScriptsFolder
	--GhostlyAnim.Parent = ScriptsFolder
	--GhostlyScript.Parent = ScriptsFolder
	PlayHere.Parent = ScriptsFolder
	GameInfo.Parent = ScriptsFolder
	MapImgs2.Parent = ScriptsFolder
	CCTV.Parent = ScriptsFolder
	Leaderboard.Parent = ScriptsFolder
	
	ScriptsVar = "Saved"
	
	repeat wait() until (ScriptsVar == "Release")
	
	Flicker.Parent = game.Workspace:FindFirstChild("Lobby").Block
	MapImgs1.Parent = game.Workspace:FindFirstChild("Lobby").MapImgs.PicFrame.Contents
	--GhostlyAnim.Parent = game.Workspace:FindFirstChild("Lobby")._NonChina.Ghostlyx_x
	--GhostlyScript.Parent = game.Workspace:FindFirstChild("Lobby")._NonChina.Ghostlyx_x
	PlayHere.Parent = game.Workspace:FindFirstChild("Lobby").PlayHere.SurfaceGui
	GameInfo.Parent = game.Workspace:FindFirstChild("Lobby").GameInfo.SurfaceGui
	MapImgs2.Parent = game.Workspace:FindFirstChild("Lobby").MapImgs.PicFrame.Contents
	if game.Workspace:FindFirstChild("Lobby"):FindFirstChild("DonationLeaderboard") then
		if game.Workspace:FindFirstChild("Lobby"):FindFirstChild("DonationLeaderboard"):FindFirstChild("LeaderUI") then
			Leaderboard.Parent = game.Workspace:FindFirstChild("Lobby"):FindFirstChild("DonationLeaderboard"):FindFirstChild("LeaderUI")
		end
	end
	
	ScriptsFolder:Destroy()
	
end)

LobbyChoices.Secret.Touched:Connect(function()
	if DisableChoose == false then
		DisableChoose = true
		
		for i, choice in pairs(LobbyChoices:GetChildren()) do
			if choice:IsA("BasePart") then
				choice.Color = Color3.fromRGB(70, 0, 0)
			end
		end
		
		for i, part in pairs(LobbyDetails:GetDescendants()) do
			if part:IsA("BasePart") then
				part.Color = Color3.fromRGB(0, 0, 0)
			end
		end
	end
end)

LobbyChoices.Choice1.ClickDetector.MouseClick:Connect(function()
        print("Works")
	if DisableChoose == false then
		DisableChoose = true

		Alert:FireAllClients("Chose 'Sunken Lobby' by Yozy.", Color3.fromRGB(0, 255, 200))

		for i, choice in pairs(LobbyChoices:GetChildren()) do
			if choice:IsA("BasePart") then
				choice.Color = Color3.fromRGB(70, 0, 0)
			end
		end
		LobbyChoices.Choice1.Color = Color3.fromRGB(0, 70, 0)

		Lobby1.Parent = game.Workspace.Lobby
		Lobby1:PivotTo(LobbyDetails:GetPivot())
		LobbyDetails:Destroy()
		Lobby1.Name = "Detail"

		for i, oldwater in pairs(LobbyWaters:GetDescendants()) do
			oldwater:Destroy()
		end

		for i, water in pairs(Lobby1:FindFirstChild("Waters"):GetChildren()) do
			if water:IsA("BasePart") and string.sub(water.Name, 1, 6) == "_Water" then
				water.Parent = LobbyWaters
			end	
		end

		for i, instance in pairs(Lobby:GetChildren()) do
			if instance.Name == "InvisibleLadder" or instance.Name == "SecretClimb" or instance.Name == "LobbyTrigger" or instance.Name == "Teleports" then
				if instance.Parent.Name ~= "Detail" then
					instance:Destroy()
				end
			end
		end

	end
end)

LobbyChoices.Choice2.ClickDetector.MouseClick:Connect(function()
        print("Works")
	if DisableChoose == false then
		DisableChoose = true
		
		Alert:FireAllClients("Chose 'Snowy Stronghold' by Sm0keyTheFox.", Color3.fromRGB(131, 201, 255))
	
		for i, choice in pairs(LobbyChoices:GetChildren()) do
			if choice:IsA("BasePart") then
				choice.Color = Color3.fromRGB(70, 0, 0)
			end
		end
		LobbyChoices.Choice2.Color = Color3.fromRGB(0, 70, 0)
	
		Lobby2.Parent = game.Workspace.Lobby
		Lobby2:PivotTo(LobbyDetails:GetPivot())
		LobbyDetails:Destroy()
		Lobby2.Name = "Detail"
	
		for i, oldwater in pairs(LobbyWaters:GetDescendants()) do
			oldwater:Destroy()
		end
	
		for i, water in pairs(Lobby2:FindFirstChild("Waters"):GetChildren()) do
			if water:IsA("BasePart") and string.sub(water.Name, 1, 6) == "_Water" then
				water.Parent = LobbyWaters
			end
		end
		
		for i, instance in pairs(Lobby:GetChildren()) do
			if instance.Name == "InvisibleLadder" or instance.Name == "SecretClimb" or instance.Name == "LobbyTrigger" or instance.Name == "Teleports" then
				if instance.Parent.Name ~= "Detail" then
					instance:Destroy()
				end
			end
		end
		
		Lobby:FindFirstChild("PlayHere").SurfaceGui.Img.ImageColor3 = Color3.fromRGB(146, 220, 255)
		Lobby:FindFirstChild("Glowy").Beam1.Color = ColorSequence.new(Color3.new(0.513725, 0.788235, 1))
		
		Lobby:FindFirstChild("PlayHere").SurfaceGui.Info:Destroy()
		Lobby2.Insertables.Info.Parent = Lobby:FindFirstChild("PlayHere").SurfaceGui
		
		Lobby:FindFirstChild("GameInfo").Position = Lobby:FindFirstChild("GameInfo").Position + Vector3.new(0, 2.6, 0)
		Lobby:FindFirstChild("GameInfo").Size = Vector3.new(17, 14, 2)
		
	end
end)

LobbyChoices.Choice3.ClickDetector.MouseClick:Connect(function()
        print("Works")
	if DisableChoose == false then
		DisableChoose = true

		Alert:FireAllClients("Chose 'Pro Lobby 2019' by GlitzBlow (Original by Crazyblox).", Color3.fromRGB(190, 0, 238))

		for i, choice in pairs(LobbyChoices:GetChildren()) do
			if choice:IsA("BasePart") then
				choice.Color = Color3.fromRGB(70, 0, 0)
			end
		end
		LobbyChoices.Choice3.Color = Color3.fromRGB(0, 70, 0)

		Lobby3.Parent = game.Workspace.Lobby
		Lobby3:PivotTo(LobbyDetails:GetPivot())
		LobbyDetails:Destroy()
		
		if Lobby3:FindFirstChild("SpinningScripts") then
			Lobby3:FindFirstChild("SpinningScripts").Parent = game.StarterPlayer.StarterPlayerScripts
			Lobby3:FindFirstChild("SpinningScripts").Enabled = true
		end
		
		Lobby3.Name = "Detail"

		for i, oldwater in pairs(LobbyWaters:GetDescendants()) do
			oldwater:Destroy()
		end

		for i, instance in pairs(Lobby:GetChildren()) do
			if instance.Name == "InvisibleLadder" or instance.Name == "SecretClimb" or instance.Name == "LobbyTrigger" or instance.Name == "Teleports" then
				if instance.Parent.Name ~= "Detail" then
					instance:Destroy()
				end
			end
		end

	end
end)

LobbyChoices.Choice4.ClickDetector.MouseClick:Connect(function()
        print("Works")
	if DisableChoose == false then
		DisableChoose = true
		
		HandleScripts()
		
		repeat wait() until (ScriptsVar == "Saved")

		Alert:FireAllClients("Chose 'Spider Dungeon' by Woomyko.", Color3.fromRGB(147, 3, 214))

		for i, choice in pairs(LobbyChoices:GetChildren()) do
			if choice:IsA("BasePart") then
				choice.Color = Color3.fromRGB(70, 0, 0)
			end
		end
		LobbyChoices.Choice4.Color = Color3.fromRGB(0, 70, 0)

		Lobby4.Parent = game.Workspace
		Lobby4:PivotTo(Lobby:GetPivot())
		Lobby:Destroy()
		Lobby4.Name = "Lobby"
		
		ScriptsVar = "Release"
	end
end)

--[[

LobbyChoices.Choice4.ClickDetector.MouseClick:Connect(function()
	if DisableChoose == false then
		DisableChoose = true

		Alert:FireAllClients("Chose 'Spider Dungeon' by Woomyko.", Color3.fromRGB(147, 3, 214))

		for i, choice in pairs(LobbyChoices:GetChildren()) do
			if choice:IsA("BasePart") then
				choice.Color = Color3.fromRGB(70, 0, 0)
			end
		end
		LobbyChoices.Choice4.Color = Color3.fromRGB(0, 70, 0)

		Lobby4.Parent = game.Workspace.Lobby
		Lobby4:PivotTo(LobbyDetails:GetPivot())
		LobbyDetails:Destroy()
		Lobby4.Name = "Detail"

		for i, oldwater in pairs(LobbyWaters:GetDescendants()) do
			oldwater:Destroy()
		end

		for i, water in pairs(Lobby4:FindFirstChild("Waters"):GetChildren()) do
			if water:IsA("BasePart") and string.sub(water.Name, 1, 6) == "_Water" then
				water.Parent = LobbyWaters
			end	
		end

		for i, instance in pairs(Lobby:GetChildren()) do
			if instance.Name == "InvisibleLadder" or instance.Name == "SecretClimb" or instance.Name == "LobbyTrigger" or instance.Name == "Teleports" then
				if instance.Parent.Name ~= "Detail" then
					instance:Destroy()
				end
			end
		end
		
		Lobby:FindFirstChild("MapImgs"):Destroy()
		Lobby:FindFirstChild("MapImgs").Position = Lobby4:FindFirstChild("MoveMapImgs").Position
		Lobby:FindFirstChild("MapImgs").Orientation = Lobby4:FindFirstChild("MoveMapImgs").Orientation
		
		if Lobby:FindFirstChild("_NonChina"):FindFirstChild("SocialMedia") then
			Lobby:FindFirstChild("_NonChina").SocialMedia.Position = Lobby4:FindFirstChild("MoveNonChina").Position
			Lobby:FindFirstChild("_NonChina").SocialMedia.Orientation = Lobby4:FindFirstChild("MoveNonChina").Orientation
		end
		
		Lobby:FindFirstChild("PlayHere").SurfaceGui.Img.ImageColor3 = Color3.fromRGB(147, 3, 214)
		Lobby:FindFirstChild("PlayHere").SurfaceGui.Info.TextColor3 = Color3.fromRGB(147, 3, 214)

		ScriptsVar = "Release"

	end
end)

]]

Explorer Section:
image
(Script is EventScript, which is in a model along with LobbyChoices)

I don’t know where it went wrong in the script so I just put the entire thing. When clicking on any of the parts, nothing happens. Not even the print statements work. There is nothing in the output, no errors or anything else. I’m completely stumped so I have no choice but to ask here. How do I fix this?

4 Likes

Before this line can you set a print to make sure it reaches the code?

Additionally print out LobbyChoices:FindFirstChild(Choice1) and see if your part is found

1 Like

What could be the problem is that the mouseclicker code is not getting runned. This could be because you have code before that, which has invoke events etc. local Lib = workspace.Multiplayer.GetMapVals:Invoke() Is there any problem here? does the invoke ever finish?

repeat wait() until (ScriptsVar == "Release")

Does this ever finish repeating? Keep in mind the lua compiler reads code from top to bottom, meaning if there are parts of the code before the mouseclicker events that never finishes repeating or invoking then the mouseclicker events aren’t getting registered

1 Like

What you could try is moving the mouseclick events to the top of the script before anything else and test if they work then, and add a couple prints starting from top to bottom and see where it stops printing, which could let you know were the issue is occouring

This part of code is wrapped anyways

I believe LobbyChoices.Choice1.ClickDetector.MouseClick:Connect(function() is never reached
However as you said Lib may never return anything. A print wouldn’t hurt

1 Like

You know even when a part touches it, it get’s triggered? So probably DisableChoose is always true. Maybe try and put it on false?

I see there is a BindableFunction under workspace.Multipler.GetMapVals
Can I have the piece of code which connects this BindableFunction?

Not sure if you know, but this is a Flood Escape 2 map, and the actual code behind that bindable is in the game and not accessible to map makers.

3 Likes

Will add print statements above of the click functions when I get home

1 Like
local LobbyDetails = Lobby:WaitForChild("Detail")

This line is the only line that I can see that would yield and stop your script from working

2 Likes

Found the problem! It was with a WaitForChild line but your solution definitely helped me figure that out :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.