Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is client updating everyone?

Asked by 5 years ago
Edited 5 years ago

I have a race like game where I use a trigger part to signal the end and show the winner. FE is enabled.

When the part is touched it sends an remoteevnt to the server with the winners name then the server sends a fireallclient to stop the race and show who won.

I kept getting an invalid playergui error but the message was showing up. So I did some test and for some reason each client is trying to update the playergui for all players.

I have just ruined it on test with two players. Player1 will update its player gui and give an error that player2 gui is invalid and player2 will update its gui and give an error that player 1 gui is invalid.

Not sure what is gong on I deconstructed my code to check if it was an interaction but get the same problem. Once I get home I can post the code if necessary, I just can keep my mind off this problem.

Trigger:

local Players = game:GetService("Players")
local localplayer = Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local timerGUI = localplayer.PlayerGui.timerGui.timerLabel --where time will be displayed
local endGameEvent = ReplicatedStorage:WaitForChild("endGameEvent")

function startTimer()
    local DEBOUNCE = false --off switch debouncer
    workspace.trigger.Touched:Connect(function(hit) --when roof (aka off switch) is touched
        if not DEBOUNCE then --so off switch work only once
            if hit.Parent:FindFirstChild("Humanoid") then --if touched by a humanoid
                print('touched')
                DEBOUNCE = true --disable off switch
                endGameEvent:FireServer(hit.parent.Name) --tell server game ended [server]
            end
        end
        DEBOUNCE = false --disable off switch
    end)
end

startTimer()

Server:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local endGameEvent = Instance.new("RemoteEvent", ReplicatedStorage) --create remove event for signaling end of game on server
endGameEvent.Name = "endGameEvent" --name remote event

local clientsEndGame = Instance.new("RemoteEvent", ReplicatedStorage) --create remove event for server to signal all clients that the game has ended
clientsEndGame.Name = "clientsEndGame" --name remote event

local function onGameEnded(player, winnerName)
    print('winner_server:: ' .. player.Name)
    clientsEndGame:FireAllClients(player, winnerName) --signal all clients to stop and display winner [client_server]
end

endGameEvent.OnServerEvent:Connect(onGameEnded) --client signaled game has ended and sent winners name

Clients:

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local localplayer = Players.LocalPlayer

local clientsEndGame = ReplicatedStorage:WaitForChild("clientsEndGame") --server trigger for ending game and sending who won
local playerGui = localplayer:WaitForChild("PlayerGui")

local function onNewPlayerFired(player, winnerName)
    print("print winner name: " .. player.Name)
    local timerGUI = player.PlayerGui.timerGui.timerLabel
    timerGUI.Text = winnerName .. " Wins!!!" --changes to winner name
end

clientsEndGame.OnClientEvent:Connect(onNewPlayerFired)
1
Of course the code is necessary. BlueGrovyle 278 — 5y
0
What BlueGrovyle said, we cannot help you unless you give us the script. MezornoIV 25 — 5y
0
Wishful thinking that someone had this problem before, but made it home and edit the post to add the codes, this is the stripped down version that still gives me the error. doncellanerdy 21 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

You didn't really post a script but I can still be of help.

:FireAllClients()

Gets every player in the server's client. https://developer.roblox.com/api-reference/function/RemoteEvent/FireAllClients

:FireClient(arg)

Gets an individual's client that is supplied in the position of

"arg"

https://developer.roblox.com/api-reference/function/RemoteEvent/FireClient

0
I want to stop the game for every player and show who won on a gui. I need to use fireallclients right?? doncellanerdy 21 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Figured it out, finally!!! My error was sending the player as a variable for fireallclients this is not necessary, I just have to reference the playergui directly since the code is running on the client.

This had me stumped for days. Thanks everyone for the help!!

0
please accept my answer if it was helpful, only if it was helpful The_Pr0fessor 595 — 5y

Answer this question