redditing Posted July 10, 2020 Share Posted July 10, 2020 My goal is that when the player clicks on the first button, the function for this button is to change for each player in his team, but unfortunately the function changes only for the person who clicked. --client side local Button1 = guiCreateButton(--There are no valid arguments ) addEventHandler("onClientGUIClick", Button1, OnTeamPlayerClickLVL1) function OnTeamPlayerClickLVL1() for i, v in pairs(getPlayersInTeam(getPlayerTeam(getLocalPlayer()))) do outputChatBox("U bought level 1 for your TEAM ^^", 0, 255, 0) removeEventHandler("onClientGUIClick", Button1, OnTeamPlayerClickLVL1) addEventHandler("onClientGUIClick", Button1, OnTeamPlayerClickLVL2) end end function OnTeamPlayerClickLVL2() for i, v in pairs(getPlayersInTeam(getPlayerTeam(getLocalPlayer()))) do outputChatBox("U bought level 2 for your TEAM ^^", 0, 255, 0) removeEventHandler("onClientGUIClick", Button1, OnTeamPlayerClickLVL2) end end -- server side RED = createTeam("Red Team", 255, 0, 0) BLUE = createTeam("Blue Team", 0, 0, 255) Here is my code that works only for ONE person and I want for the current team Link to comment
MrKAREEM Posted July 10, 2020 Share Posted July 10, 2020 in the lines 8 and 9 change getLocalPlayer() with getElementsByType('player') 6 hours ago, redditing said: My goal is that when the player clicks on the first button, the function for this button is to change for each player in his team, but unfortunately the function changes only for the person who clicked. --client side local Button1 = guiCreateButton(--There are no valid arguments ) addEventHandler("onClientGUIClick", Button1, OnTeamPlayerClickLVL1) function OnTeamPlayerClickLVL1() for i, v in pairs(getPlayersInTeam(getPlayerTeam(getElementsByType('player')))) do outputChatBox("U bought level 1 for your TEAM ^^", 0, 255, 0) removeEventHandler("onClientGUIClick", Button1, OnTeamPlayerClickLVL1) addEventHandler("onClientGUIClick", Button1, OnTeamPlayerClickLVL2) end end function OnTeamPlayerClickLVL2() for i, v in pairs(getPlayersInTeam(getPlayerTeam(getElementsByType('player')))) do outputChatBox("U bought level 2 for your TEAM ^^", 0, 255, 0) removeEventHandler("onClientGUIClick", Button1, OnTeamPlayerClickLVL2) end end -- server side RED = createTeam("Red Team", 255, 0, 0) BLUE = createTeam("Blue Team", 0, 0, 255) Here is my code that works only for ONE person and I want for the current team Link to comment
Sisqo0 Posted July 10, 2020 Share Posted July 10, 2020 (edited) it's client side so the function will work for the player who clicked only.. i don't even think that getElementsByType('player') would work but you can try. Edited July 10, 2020 by Sisqo0 Link to comment
redditing Posted July 10, 2020 Author Share Posted July 10, 2020 29 minutes ago, Sisqo0 said: it's client side so the function will work for the player who clicked only.. i don't even think that getElementsByType('player') would work but you can try. 3 hours ago, MrKAREEM said: in the lines 8 and 9 change getLocalPlayer() with getElementsByType('player') People, I want to change the event not for one player but for one team in which the player is. So how can I do it? Because if I click this button, this button changes only for one person and not for the whole team Link to comment
Sisqo0 Posted July 10, 2020 Share Posted July 10, 2020 which event? do you mean outputChatBox ? to appear for all players in team? Link to comment
redditing Posted July 10, 2020 Author Share Posted July 10, 2020 11 minutes ago, Sisqo0 said: which event? do you mean outputChatBox ? to appear for all players in team? removeEventHandler("onClientGUIClick", Button1, OnTeamPlayerClickLVL1) addEventHandler("onClientGUIClick", Button1, OnTeamPlayerClickLVL2) Link to comment
Sisqo0 Posted July 10, 2020 Share Posted July 10, 2020 (edited) here is a way. maybe it's not perfect but addEventHandler & removeEventHandler work for the client only so you need to find another way to reach your goal and here is one. --client side local Button1 = guiCreateButton(--There are no valid arguments ) addEventHandler("onClientGUIClick", Button1, OnTeamPlayerClickLVL) function OnTeamPlayerClickLVL() local team = getPlayerTeam(getLocalPlayer()) local level = (getElementData(team,"level") or 0) for i, v in pairs(getPlayersInTeam(team)) do if level == 0 then outputChatBox("U bought level 1 for your TEAM ^^", 0, 255, 0) setElementData(team,"level",1) elseif level == 1 then outputChatBox("U bought level 2 for your Team ^^", 0,255,0) setElementData(team,"level",2) removeEventHandler("onClientGUIClick", Button1,OnTeamPlayerClickLVL) end end end -- server side RED = createTeam("Red Team", 255, 0, 0) BLUE = createTeam("Blue Team", 0, 0, 255) Edited July 10, 2020 by Sisqo0 Link to comment
redditing Posted July 10, 2020 Author Share Posted July 10, 2020 24 minutes ago, Sisqo0 said: here is a way. maybe it's not perfect but addEventHandler & removeEventHandler work for the client only so you need to find another way to reach your goal and here is one. --client side local Button1 = guiCreateButton(--There are no valid arguments ) addEventHandler("onClientGUIClick", Button1, OnTeamPlayerClickLVL) function OnTeamPlayerClickLVL() local team = getPlayerTeam(getLocalPlayer()) local level = (getElementData(team,"level") or 0) for i, v in pairs(getPlayersInTeam(team)) do if level == 0 then outputChatBox("U bought level 1 for your TEAM ^^", 0, 255, 0) setElementData(team,"level",1) elseif level == 1 then outputChatBox("U bought level 2 for your Team ^^", 0,255,0) setElementData(team,"level",2) removeEventHandler("onClientGUIClick", Button1,OnTeamPlayerClickLVL) end end end -- server side RED = createTeam("Red Team", 255, 0, 0) BLUE = createTeam("Blue Team", 0, 0, 255) And will remove this button event for each player on the team? ("OnClientGUIClick ') Link to comment
Sisqo0 Posted July 10, 2020 Share Posted July 10, 2020 no, it will remove event for the player who clicked only but if any player of that team pressed on button.. nothing would happen as someone before pressed on it. Btw you don't need to remove it from all players if it doesn't affect what you want to do but if you still want to remove it, then i have no idea but even if there's a way, i don't think it can be done by client only ( maybe you need to use server side). good luck. 1 Link to comment
N3xT Posted July 11, 2020 Share Posted July 11, 2020 You need to trigger an event to make this happens, so when the player presses the button you send a server-side trigger, furthermore, you send it back again to his teammates and then do whatever you want to them triggerClientEvent triggerServerEvent Link to comment
redditing Posted July 11, 2020 Author Share Posted July 11, 2020 1 hour ago, N3xT said: You need to trigger an event to make this happens, so when the player presses the button you send a server-side trigger, furthermore, you send it back again to his teammates and then do whatever you want to them triggerClientEvent triggerServerEvent Good idea but i think about lags with server after that Link to comment
Scripting Moderators xLive Posted July 11, 2020 Scripting Moderators Share Posted July 11, 2020 (edited) 1 hour ago, redditing said: Good idea but i think about lags with server after that Make a simple cooldown disable the button with guiSetEnabled and enable it after 5 secs for example with setTimer btw @Sisqo0 you can use the global variables instead of these functions getRootElement() - root getLocalPlayer() - localPlayer getResourceRootElement() - resourceRoot Edited July 11, 2020 by xLive 1 Link to comment
Sisqo0 Posted July 11, 2020 Share Posted July 11, 2020 5 hours ago, xLive said: btw @Sisqo0 you can use the global variables instead of these functions getRootElement() - root getLocalPlayer() - localPlayer getResourceRootElement() - resourceRoot Yes i know them. Anyways thanks Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now