How to run a code when a remote event is run, only once????
Soooooo, i was trying to do something, and one thing i noticed is that when an event is run, its constantly run until another event is run, i dont get it. my code:
RoleHandler (local script, located in starterplayerscripts):
01 | local roundStart = game.ReplicatedStorage.remoteEvents.round.roundStart |
02 | local roundEnd = game.ReplicatedStorage.remoteEvents.round.roundEnd |
04 | local replicatedStorage = game.ReplicatedStorage |
05 | local roleFolder = game.ReplicatedStorage.remoteEvents.roles |
07 | local murdererChosen = game.ReplicatedStorage.remoteEvents.roles.murderer |
08 | local sheriffChosen = game.ReplicatedStorage.remoteEvents.roles.sheriff |
09 | local innocentChosen = game.ReplicatedStorage.remoteEvents.roles.innocent |
10 | local neutral = game.ReplicatedStorage.remoteEvents.roles.neutral |
12 | local randomRole = math.random( 1 , 3 ) |
13 | local theChosenRole = game.ReplicatedStorage.TheChosenRole |
16 | roundStart.OnClientEvent:Connect( function () |
18 | if randomRole = = 3 then |
20 | murdererChosen:FireServer(randomRole) |
21 | theChosenRole.Value = "MURDERER" |
22 | elseif randomRole = = 2 then |
24 | sheriffChosen:FireServer(randomRole) |
25 | theChosenRole.Value = "SHERIFF" |
26 | elseif randomRole = = 1 then |
28 | innocentChosen:FireServer(randomRole) |
29 | theChosenRole.Value = "INNOCENT" |
33 | roundEnd.OnClientEvent:Connect( function () |
35 | neutral:FireServer(randomRole) |
36 | theChosenRole.Value = "NEUTRAL" |
Display Role(server script, located in a GUI that is in starter GUI)
01 | local chosenNumber = game.ReplicatedStorage.chosenNumber |
02 | local status = script.Parent.TextLabel |
03 | local tof = game.ReplicatedStorage:WaitForChild( "displayChosenTOF" ) |
04 | local chosenRole = game.ReplicatedStorage:WaitForChild( "TheChosenRole" ) |
05 | local inround = game.ReplicatedStorage.InRound |
07 | local murdererChosen = game.ReplicatedStorage.remoteEvents.roles.murderer |
08 | local sheriffChosen = game.ReplicatedStorage.remoteEvents.roles.sheriff |
09 | local innocentChosen = game.ReplicatedStorage.remoteEvents.roles.innocent |
10 | local neutral = game.ReplicatedStorage.remoteEvents.roles.neutral |
14 | local roundStart = game.ReplicatedStorage.remoteEvents.round.roundStart |
15 | local roundEnd = game.ReplicatedStorage.remoteEvents.round.roundEnd |
17 | innocentChosen.OnServerEvent:Connect( function (player, randomRole) |
18 | status.TextColor 3 = Color 3. new( 3 / 255 , 255 / 255 , 19 / 255 ) |
19 | status.Text = "INNOCENT" |
22 | murdererChosen.OnServerEvent:Connect( function (player, randomRole) |
23 | status.TextColor 3 = Color 3. new( 255 / 255 , 0 / 255 , 4 / 255 ) |
24 | status.Text = "MURDERER" |
27 | sheriffChosen.OnServerEvent:Connect( function (player, randomRole) |
28 | status.TextColor 3 = Color 3. new( 16 / 255 , 40 / 255 , 255 / 255 ) |
29 | status.Text = "SHERIFF" |
32 | neutral.OnServerEvent:Connect( function (player, randomRole) |
33 | status.TextColor 3 = Color 3. new( 255 / 255 , 255 / 255 , 255 / 255 ) |
34 | status.Text = "IN LOBBY" |
Also, I didn't put a code to this, but I was trying to make it so that it appears for 5 seconds and it disappears, that works, but when it disappears it appears once again and continuously does that until a new event is run.
btw the --code here comments are just because I was doing something before that and marked that there.