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

Asked

Viewed 200 times

0

I’ve already tried

remoteEvent:FireAllClients()
remoteEvent:FireServer()

but it didn’t work. It said that FireServer could only be used by the client. I 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 didn’t work either. Only when I changed the location of the script to StarterPlayer.StarterPlayerScripts and changing the argument of FireClient for game.StarterPlayer.StarterPlayerScripts.LocalScript worked.

Then I changed the argument from FireClient for game.Players.Player1 (test player in Studio) and also worked.

But to complicate it I cannot insert the local script into game.StarterPlayer.StarterPlayerScripts because this folder inserts everything it has in it (including non-scripting objects) into a folder called PlayerScripts within a player entering the game, all players will be left with the localscript that will fire the remote Event, which cannot be fired several times at a time.

BUT I FINALLY need a script that fires the remote Event to the server and client.

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

1 answer

0


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

detail:objValue is the object of the master client

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 that into the local 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)

In case it doesn’t work, I figured out another way to fire at the client and server. Simply create a Bindableevent and insert a Remoteevent inside it.

Insert this into 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 haven’t tried it yet but I think it will work.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.