Jump to content

GUI window appears 2 times


kuwalda

Recommended Posts

I have been creating automatic race system and for now all was fine, until I found a little bug that I am unable to find and fix.

Script idea:

  
--[sERVER] Script considers to make race or not  
function raceConsider( ) 
     if getPlayerCount() >= 2 then 
     if raceActive[1] == "false" then 
         triggerClientEvent ( "showRaceInfo", getRootElement()) 
        raceActive[1] = "true" 
          end 
     end 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), raceConsider ) 
  
--[CLIENT] Sets timer to allow player login, so he can freely look at GUI 
function showRaceInformation ( ) 
    setTimer ( function ()triggerServerEvent( "needRaceGUI", root)end, 15000, 1) 
end 
addEvent( "showRaceInfo", true ) 
addEventHandler( "showRaceInfo", getRootElement(), showRaceInformation ) 
  
--[sERVER] Gathers information for race 
function getRaceGUI( ) 
    raceRikotajs = Rikotajs[ math.random( 1,#Rikotajs ) ] 
    triggerClientEvent(root, "gotRaceGUI", root, raceRikotajs) 
end 
addEvent( "needRaceGUI", true ) 
addEventHandler( "needRaceGUI", root, getRaceGUI ) 
  
--[CLIENT] And displays GUI 
function showRaceGUI ( raceRikotajs ) 
    ... 
end 
addEvent( "gotRaceGUI", true ) 
addEventHandler( "gotRaceGUI", getRootElement(), showRaceGUI ) 
  

Problem is: when I am connected to server and my friend joins it - all works perfectly and fine, but when I reset raceActive[1] = "true" to raceActive[1] = "false" and my friend joins this GUI is displaying 2 times. How to make it apper only 1 time? Where did I go wrong?

Link to comment
Well, you put it to show to everyone, since you're triggering the client side event "showRaceInfo" to getRootElement.

I want it to show to everyone, but I dont want it to trigger 2 times and show 2 GUIs at once.

As I said, GUI shows only once for each player when I trigger it first time, but when I trigger it second time, it shows 2 GUIs per player.

Where is the GUI ?
  
--[CLIENT] And displays GUI 
function showRaceGUI ( raceRikotajs ) 
    ... 
end 
addEvent( "gotRaceGUI", true ) 
addEventHandler( "gotRaceGUI", getRootElement(), showRaceGUI ) 
  

With GUI everything should be fine, there is just styling options.

As I understand problem is somewhere in first or second "step"

Edited by Guest
Link to comment
Well, you're obviously creating the GUI everytime, instead of setting it visible.

Yes, because this GUI tells information about race event and it gets random values everytime, so information in this GUI is changing.

  
raceRikotajs = Rikotajs[ math.random( 1,#Rikotajs ) ] 
  

Link to comment
But, there's no need to do that, you can use the function guiSetText.

I know, but that is not my problem. The problem is like this:

* I join the server

* My friend join the server

* event is triggered

* GUI pops out for both of us

* My friend leaves the server

* I reset value to raceActive[1] = "false"

* My friend join the server

* event is triggered

* GUI pops out for both of us and ANOTHER GUI pops out on top of last one

So basiclly event is being triggered 2 times, but I have no idea what causes it.

Link to comment
Is triggered 2 times because that's how your script works, when you reset the value to "false", you should also destroy the GUI if exists.

No, there is button in GUI to close the last one. If I wouldnt close it on first time, there would be in total of 3 GUIs when event is triggered 2nd time

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...