Currently, I have a remote event that will run once if there is one player in-game or if two players are in-game it will run twice. And so on and so on. The Remote Event should only run once regardless of players.
Local Script
The player clicks on a Create Game button. Then the GUI changes temporarily until a password is entered under four characters. This triggers an event and also the PWHold value goes to one so the player can’t create another Private game. Then the GUI changes so the player is on the page that shows Private Games when if-else statement is over. The information sent over by this event is the player and password the player created.
-- Create Private Game
local function ActivatedCreate()
print(PWHold.Value)
print(PWHold1.Value)
PrivateGui()
wait()
PRIVATE.BackgroundColor3 = Color3.new(1, 1, 1)
JOIN.BackgroundColor3 = Color3.new(1, 1, 1)
CREATE.BackgroundColor3 = Color3.new(0.333333, 1, 0)
PASSWORD.Visible = true
PWHeader.Visible = true
MainGuiOff()
PASSWORD.FocusLost:connect(function(enterPressed)
if string.len(PASSWORD.Text) > 4 then
print("Over the limit")
elseif PASSWORD.Text == PASSWORD.Text:sub(1,4) then
if enterPressed and PWHold.Value == 0 then
local PW = PASSWORD.Text
PWHold.Value = 1
PWEvent:FireServer(PW, player)
end
end
PWHeader.Visible = false
PASSWORD.Visible = false
MainGuiOn()
PRIVATE.BackgroundColor3 = Color3.new(0.333333, 1, 0)
CREATE.BackgroundColor3 = Color3.new(1, 1, 1)
end)
end
CREATE.Activated:Connect(ActivatedCreate)
Server Script
Each Private Party has a true or false value that determines if a party is true or not. This is the PartyCreate values. When the event started after someone made a password for a party to be created. The code checks through the if else statement to find the lowest number private party slot available by seeing if the PartyCreate value is false. It then takes the password to assign it to a string object to be stored for future use so other players can join the party. If a PartyCreate value is changed it will do additional logic that isn’t finished yet. I haven’t finished it due to the bug of this remote event running multiple times.
local function CreatePW(player, PW)
print(player.Name) -- Prints one player name, but shows multiple times based off player count in game
print(PW) -- Same as print statement above, but for PW
if PartyCreate1.Value == false then
PW1 = PW
PartyCreate1.Value = true
--CreatePrivate1(player)
elseif PartyCreate2.Value == false then
PW2 = PW
PartyCreate2.Value = true
elseif PartyCreate3.Value == false then
PW3 = PW
PartyCreate3.Value = true
end
end
PWEvent.OnServerEvent:Connect(CreatePW)
How can I make a Remote Event Run once based on the player triggering the event instead by the number of people in game? Currently the remote Event “PWEvent” triggered in the local script x amount of times based off players in game.