Need help with remote event problem

Hi there! I’m BluestOfFlames, and I’m having a little bit of trouble with my script(s).
Any and all help is appreciated!

I have a Home Screen Function, and the server and client communicate to activate it through remote events. The function is mostly made up of 3 different functions; However they all have the same problem, so I’ll just show one

	local function GUIhovers()		--Hover system
		
                print("GUI function")
		local NewColor = Color3.new(0.545098, 0.545098, 0.545098)	--Define Color Codes
		local OldColor = Color3.new(1, 1, 1)
		
		local function MouseEntered(GuiObject)
			GuiObject.TextColor3 = NewColor
		end
		
		local function MouseLeaved(GuiObject)
			GuiObject.TextColor3 = OldColor
		end
		
		PlayButton.MouseEnter:Connect(function()
			print("PLay Button is Hovered Over")
             MouseEntered(PlayButton)
		end)		--enact hovers
		EndingsButton.MouseEnter:Connect(function()
			MouseEntered(EndingsButton)
		end)
		
		UpdateLogButton.MouseEnter:Connect(function()
			MouseEntered(UpdateLogButton)
		end)
		
		PlayButton.MouseLeave:Connect(function()
			MouseLeaved(PlayButton)
		end)
		
		EndingsButton.MouseLeave:Connect(function()
			MouseLeaved(EndingsButton)
		end)
		
		UpdateLogButton.MouseLeave:Connect(function()
			MouseLeaved(UpdateLogButton)
		end)
		
	end

Here is the remote event which the client uses to tell the server to continue.

ReadyToCon:FireServer()		--Fire server to continue

Here is the receiving function for that remote event.

ReadyToCon.OnServerEvent:Connect(function()		--Activate Gui homescreen again
		
	for i, v in pairs(Players:GetChildren()) do
		ClientSet:FireClient(v)
	end
	
end)

Here is the receiving function for the ClientSet remote event:

StartingTrigger.OnClientEvent:Connect(function()	--When remote event is called, enact the HomeScreenFunction (same for below)
	
	HomeScreenfunction()
	
end)

Here’s the player added function

ReadyToCon.OnServerEvent:Connect(function()		--Activate Gui homescreen again
		
	for i, v in pairs(Players:GetChildren()) do
		ClientSet:FireClient(v)
	end
	
end)

Summary: When a player is added, the clientset remote event is fired. The client then connects the homescreen function to it, and then, later, the client tells the server to “continue”, in which the server goes and fires the clientset remote event AGAIN.

Now here’s the problem. Whenever the remote event is called the FIRST time, everything works just fine. But the SECOND time the remote event is called, the print function that says “Play Button is hovered over” is called TWICE, even if I hovered into it just once. However, the print function that says “GUI function” is only enacted once each time, like it should be. Here’s a video better explaining the problem.

I have a feeling this has to do with disconnecting and connecting remote events, but I have no idea how to implement that. Sorry if this wasn’t explained very well.

1 Like

Does the HomeScreenfunction() clone the GUI at all in any sort of way?

1 Like

I don’t believe it does. The GUI’s are already created, the function just makes it so that the text changes color when it is hovered over.

https://developer.roblox.com/en-us/recipes/How-to-disconnect-an-event-connection
Maybe this then? Also if you’re adding a PlayerAdded function to fire all clients, I think that would always fire for everyone whenever they join the game so you might wanna change that

Thank you! The article is useful, but I want to be able to connect it again at a certain time. Also, my game is single player, so fire all clients, in a sense, works the same as firing a single client.

Ah k, Hmmm try adding debounces to the MouseEnter and MouseLeave functions? You could check to see that it’ll fire once, but it’s just a minor example

1 Like

Hmm, that didn’t work. The debounce is working, but it still does the same thing. Thank you anyways!