How do I trigger a remote event for the server and client in the same script in ROBLOX Studio?

0

I've already tried

remoteEvent:FireAllClients()
remoteEvent:FireServer()

But it did not work. It said FireServer could only be used by the client. I've also tried:

--No server script em workspace
remoteEvent:FireClient(script.LocalScript)

--No local script em workspace.Script
remoteEvent.OnClientEvent:connect(function()
    remoteEvent:FireServer()
end)

But it also did not work. Only when I changed the location of the local script to StarterPlayer.StarterPlayerScripts and changing the argument from FireClient to game.StarterPlayer.StarterPlayerScripts.LocalScript worked.

I then changed the argument from FireClient to game.Players.Player1 (the test player in Studio) and it also worked.

But to complicate, I can not insert the local script in game.StarterPlayer.StarterPlayerScripts because this folder inserts everything in it (including non-scripts) into a folder called PlayerScripts inside a player that enters the game, all players will be left with the localscript that will trigger the remote event, which can not be fired several times at once.

But at last I need a script that triggers the remote event for the server and the client.

PS: For those who want to help me, but do not have much experience with ROBLOX Studio, I will explain briefly: Server scripts will only act on the server and local scripts will act on the client (on the player's PC) and remote events are objects in the which has 2 special events, one will be detected by the server scripts ( OnServerEvent ) and the other will be detected by the local scripts ( OnClientEvent ) and that can trigger these events when "listening" the functions FireServer , FireClient and FireAllClients , which I do not need to explain what they will do because if you play moon games it is because you know English

    
asked by anonymous 25.02.2017 / 00:28

1 answer

0

Well ... I found out for myself. And I called this method of "Master Client". Basically I added a remote event, an object value, a server script in workspace and a local script in StarterPlayer.StarterPlayerScripts . I wrote this in the server script:

detail: objValue is the master client object

game.Players.PlayerAdded:connect(function(player)--Bloco que irá ser executado quando um jogador entrar
    if objValue.Value==nil then--Vê se há um master client.Se não tiver...
        objValue.Value=player --Irá fazer desse jogador o master client
        print('master client agr e '..objValue.Value.Name..' :D:D:D')
    end
end)

game.Players.PlayerRemoving:connect(function(player) --Bloco que irá ser executado quando um jogador sair
    if player==objValue.Value then--Vê se esse jogador que saiu é o master client.Se é...
        print('master client saiu :(')
        objValue.Value=game.Players:GetPlayers()[1] --Irá definir um novo master client
        print('novo master client e '..objValue.Value.Name..'yaya :D:D:D')
    end
end)


rEvent.OnServerEvent:connect(function()
    print'e voala! evento disparado para o client e o server!'
end)
    while wait(1) do
        rEvent:FireAllClients()
    end

rEvent:FireAllClients()

And I inserted this into the local script in StarterPlayer.StarterPlayerScripts

rEvent.OnClientEvent:connect(function() --Bloco que irá ser executar quando OnClientEvent for disparado
    if objValue.Value==game.Players.LocalPlayer then --Vê se o master client é o jogador local.Se é...
        print'sou euuu o tiriricaaa'
        rEvent:FireServer()
    else --Senão...
        print'nao sou eu :('
    end
end)

If it does not work, I've figured out another way to fire both the client and the server. Simply create a BindableEvent and insert a RemoteEvent inside it.

Enter this in the server script

bindableEvent.Event:connect(function()
    remoteEvent:FireAllClients()
end)

bindableEvent:Fire()

and then insert this into the local script

remoteEvent.OnClientEvent:connect(function()
    print'funcionou aaaeeeeeeeeeeeeeeeeeeeeeeeeeee'
end)

I have not tested it but I think it will work.

    
26.02.2017 / 01:18