Mousebuttonclick doesn't work at first time

For some reason, first time doesn’t work. But others after that it is
Here’s the script

script.Parent.MouseEnter:Connect(function()
game.SoundService.Click:Play()
end)

local function major(v)
local x = game.Players.LocalPlayer.PlayerGui.Guis.Mythipedia.Main.ScrollingFrame.None:Clone()
x.ImageButton.Image = v.SurfaceGui.ImageLabel.Image
x.Name = v.Name
x.Description.Value = v.Setting.Description.Value
x.Difficulty.Value = v.Setting.Difficulty.Value
x.Hint.Value = v.Setting.Hint.Value
if game.Players.LocalPlayer.Database[v.Name].Value == 0 then
x.ImageButton.BackgroundColor3 = Color3.new(0.372549, 0.372549, 0.372549)
else
x.IsFound.Value = true
if x.Difficulty.Value == “Easy” then
x.ImageButton.BackgroundColor3 = Color3.new(0, 0.666667, 1)
elseif x.Difficulty.Value == “Normal” then
x.ImageButton.BackgroundColor3 = Color3.new(0.333333, 0.666667, 0)
elseif x.Difficulty.Value == “Hard” then
x.ImageButton.BackgroundColor3 = Color3.new(1, 0, 0)
elseif x.Difficulty.Value == “Epic” then
x.ImageButton.BackgroundColor3 = Color3.new(0.666667, 0.666667, 1)
elseif x.Difficulty.Value == “Legendary” then
x.ImageButton.BackgroundColor3 = Color3.new(1, 0.85098, 0)
end
end
x.Parent = game.Players.LocalPlayer.PlayerGui.Guis.Mythipedia.Main.ScrollingFrame
end

local function bringback()
for n,t in pairs(game.ReplicatedStorage.Creatures:GetChildren()) do
for i,v in pairs(game.ReplicatedStorage.Creatures[t.Name]:GetChildren()) do
if v.Setting.Zone.Value == script.Parent.Parent.Sorting.Value then
major(v)
elseif script.Parent.Parent.Sorting.Value == “None” then
major(v)
end
end
end
end

local function diff(a)
for i,v in pairs(game.ReplicatedStorage.Creatures[a]:GetChildren()) do
if v.Setting.Zone.Value == script.Parent.Parent.Sorting.Value then
major(v)
elseif script.Parent.Parent.Sorting.Value == “None” then
major(v)
end
end
end

local function remove()
for i,v in pairs(game.Players.LocalPlayer.PlayerGui.Guis.Mythipedia.Main.ScrollingFrame:GetChildren()) do
if v:IsA(“Frame”) and v.Name ~= “None” then
v:Destroy()
end
end
end

local creatureFolders = {
game.ReplicatedStorage.Creatures.Easy,
game.ReplicatedStorage.Creatures.Normal,
game.ReplicatedStorage.Creatures.Hard,
game.ReplicatedStorage.Creatures.Epic,
game.ReplicatedStorage.Creatures.Legendary
}

script.Parent.Parent.Sorting.Changed:Connect(function(re)
remove()
local view = “”
if script.Parent.Text == “View: All” then
view = “All”
elseif script.Parent.Text == “View: Easy” then
view = “Easy”
elseif script.Parent.Text == “View: Normal” then
view = “Normal”
elseif script.Parent.Text == “View: Hard” then
view = “Hard”
elseif script.Parent.Text == “View: Epic” then
view = “Epic”
elseif script.Parent.Text == “View: Legendary” then
view = “Legendary”
end
for _, folder in pairs(creatureFolders) do
for _, v in pairs(folder:GetChildren()) do
if v.Setting.Zone.Value == script.Parent.Parent.Sorting.Value and v.Setting.Difficulty.Value == view then
major(v)
elseif v.Setting.Zone.Value == script.Parent.Parent.Sorting.Value and view == “All” then
major(v)
elseif script.Parent.Parent.Sorting.Value == “None” and view == “All” then
major(v)
elseif script.Parent.Parent.Sorting.Value == “None” and v.Setting.Difficulty.Value == view then
major(v)
end
end
end
end)

script.Parent.MouseButton1Click:Connect(function(e)
game.SoundService.Btn:Play()
if script.Parent.Text == “View: All” then
script.Parent.Text = “View: Easy”
remove()
diff(“Easy”)
elseif script.Parent.Text == “View: Easy” then
script.Parent.Text = “View: Normal”
remove()
diff(“Normal”)
elseif script.Parent.Text == “View: Normal” then
script.Parent.Text = “View: Hard”
remove()
diff(“Hard”)
elseif script.Parent.Text == “View: Hard” then
script.Parent.Text = “View: Epic”
remove()
diff(“Epic”)
elseif script.Parent.Text == “View: Epic” then
script.Parent.Text = “View: Legendary”
remove()
diff(“Legendary”)
elseif script.Parent.Text == “View: Legendary” then
script.Parent.Text = “View: All”
remove()
bringback()
end
end)


Clip if you want to see how it is bugged

Please refrain from pasting large amounts of code like this.

Use three backticks to start code and three to end

You can also click on the </> symbol when editing posts.

Let me look into your code & video.

Alright

script.Parent.MouseEnter:Connect(function()
	game.SoundService.Click:Play()
end)

local function major(v)
	local x = game.Players.LocalPlayer.PlayerGui.Guis.Mythipedia.Main.ScrollingFrame.None:Clone()
	x.ImageButton.Image = v.SurfaceGui.ImageLabel.Image
	x.Name = v.Name
	x.Description.Value = v.Setting.Description.Value
	x.Difficulty.Value = v.Setting.Difficulty.Value
	x.Hint.Value = v.Setting.Hint.Value
	if game.Players.LocalPlayer.Database[v.Name].Value == 0 then
		x.ImageButton.BackgroundColor3 = Color3.new(0.372549, 0.372549, 0.372549)
	else
		x.IsFound.Value = true
		if x.Difficulty.Value == "Easy" then
			x.ImageButton.BackgroundColor3 = Color3.new(0, 0.666667, 1)
		elseif x.Difficulty.Value == "Normal" then
			x.ImageButton.BackgroundColor3 = Color3.new(0.333333, 0.666667, 0)
		elseif x.Difficulty.Value == "Hard" then
			x.ImageButton.BackgroundColor3 = Color3.new(1, 0, 0)
		elseif x.Difficulty.Value == "Epic" then
			x.ImageButton.BackgroundColor3 = Color3.new(0.666667, 0.666667, 1)
		elseif x.Difficulty.Value == "Legendary" then
			x.ImageButton.BackgroundColor3 = Color3.new(1, 0.85098, 0)
		end
	end
	x.Parent = game.Players.LocalPlayer.PlayerGui.Guis.Mythipedia.Main.ScrollingFrame
end

local function bringback()
	for n,t in pairs(game.ReplicatedStorage.Creatures:GetChildren()) do
		for i,v in pairs(game.ReplicatedStorage.Creatures[t.Name]:GetChildren()) do
			if v.Setting.Zone.Value == script.Parent.Parent.Sorting.Value  then
				major(v)
			elseif script.Parent.Parent.Sorting.Value == "None" then
				major(v)
			end
		end
	end
end

local function diff(a)
	for i,v in pairs(game.ReplicatedStorage.Creatures[a]:GetChildren()) do
		if v.Setting.Zone.Value == script.Parent.Parent.Sorting.Value  then
			major(v)
		elseif script.Parent.Parent.Sorting.Value == "None" then
			major(v)
		end
	end
end

local function remove()
	for i,v in pairs(game.Players.LocalPlayer.PlayerGui.Guis.Mythipedia.Main.ScrollingFrame:GetChildren()) do
		if v:IsA("Frame") and v.Name ~= "None" then
			v:Destroy()
		end
	end
end

local creatureFolders = {
	game.ReplicatedStorage.Creatures.Easy,
	game.ReplicatedStorage.Creatures.Normal,
	game.ReplicatedStorage.Creatures.Hard,
	game.ReplicatedStorage.Creatures.Epic,
	game.ReplicatedStorage.Creatures.Legendary
}

script.Parent.Parent.Sorting.Changed:Connect(function(re)
	remove()
	local view = ""
	if script.Parent.Text == "View: All" then
		view = "All"
	elseif script.Parent.Text == "View: Easy" then
		view = "Easy"
	elseif script.Parent.Text == "View: Normal" then
		view = "Normal"
	elseif script.Parent.Text == "View: Hard" then
		view = "Hard"
	elseif script.Parent.Text == "View: Epic" then
		view = "Epic"
	elseif script.Parent.Text == "View: Legendary" then
		view = "Legendary"
	end 
	for _, folder in pairs(creatureFolders) do
		for _, v in pairs(folder:GetChildren()) do
			if v.Setting.Zone.Value == script.Parent.Parent.Sorting.Value and v.Setting.Difficulty.Value == view  then
				major(v)
			elseif v.Setting.Zone.Value == script.Parent.Parent.Sorting.Value and view == "All" then
				major(v)
			elseif script.Parent.Parent.Sorting.Value == "None" and view == "All" then
				major(v)
			elseif script.Parent.Parent.Sorting.Value == "None" and v.Setting.Difficulty.Value == view then
				major(v)
			end
		end
	end
end)

script.Parent.MouseButton1Click:Connect(function(e)
	game.SoundService.Btn:Play()
	if script.Parent.Text == "View: All" then
		script.Parent.Text = "View: Easy"
		remove()
		diff("Easy")
	elseif script.Parent.Text == "View: Easy" then
		script.Parent.Text = "View: Normal"
		remove()
		diff("Normal")
	elseif script.Parent.Text == "View: Normal" then
		script.Parent.Text = "View: Hard"
		remove()
		diff("Hard")
	elseif script.Parent.Text == "View: Hard" then
		script.Parent.Text = "View: Epic"
		remove()
		diff("Epic")
	elseif script.Parent.Text == "View: Epic" then
		script.Parent.Text = "View: Legendary"
		remove()
		diff("Legendary")
	elseif script.Parent.Text == "View: Legendary" then
		script.Parent.Text = "View: All"
		remove()
		bringback()
	end
end)

Soo I’m not sure because well… I don’t really have access to the place and the Gui but here is what I think:

It’s because the diff() function doesn’t account for when the sorting is set to “None”. Basically, it’s filtering by zone, but if no zone is selected, it skips everything.

Try this function instead

local function diff(a)
	for i, v in pairs(game.ReplicatedStorage.Creatures[a]:GetChildren()) do
		if script.Parent.Parent.Sorting.Value == "None" then
			major(v)
		elseif v.Setting.Zone.Value == script.Parent.Parent.Sorting.Value then
			major(v)
		end
	end
end

Please let me know how it went.

Not working. Also sorry for late reply, my PC have some problem.

Okay,

Sadly I can’t do anything else because I don’t have more info.
Hope you resolve it!

alright, thankyou for help anyways

I just figure that value in the sorting is “”, which makes script not working. Here’s the solution if anyone found same problem

1 Like