Server side not running upon fired

idk why it works when i print on client but when it gets to server it does nothing

Client:

local function LeaveGame(Member)
	if Member ~= Player then
		KickMember(Member)
		
	else
		DisbandEvent:FireServer(Party)
		
	end
end

Players.PlayerRemoving:Connect(LeaveGame)

Server:

local function DisbandServer(Host, Party)
	for _, Player in Players:GetChildren() do
		local PlayerGui = Player.PlayerGui
		
		local ServerGui = PlayerGui.ServerGui
		local ServerScroll = ServerGui.ServerScroll
		
		local ServerImageCopy = ServerScroll:FindFirstChild(Host.Name)
		ServerImageCopy:Destroy()

	end
	
	for _, Player in Party do
		DisbandEvent:FireClient(Player)
		
	end
end

DisbandEvent.OnServerEvent:Connect(DisbandServer)
1 Like

I would personally handle any event or action related to a “Lobby/Party” on the server because, remember, you can never trust the client!

Therefore, what I’d recommend is handling the PlayerRemoving event on the server. The only events I’d handle on the client are when the player sends a request to the server to join any lobby or party.

On the other hand, I’d handle UI-related tasks on the client and not on the server.

But my data is on the client, how would i get the data on the server then

I suppose you’d have to reorganize your code a bit. With the current piece of code, any exploiter can send a request to the server to disband the lobby, as well as it can cause some issues since it is being handled on client.

Also always have sanity checks on the server .

It doesn’t work because the server script can’t look in the PlayerGui
Try this instead on the local script:

local function LeaveGame(Member)
	if Member ~= Player then
		KickMember(Member)
		
	else
		for _, Player in pairs(Players:GetChildren()) do
	      	local PlayerGui = Player.PlayerGui
		
		    local ServerGui = PlayerGui.ServerGui
		    local ServerScroll = ServerGui.ServerScroll
		
		    local ServerImageCopy = ServerScroll:FindFirstChild(Host.Name)
		    ServerImageCopy:Destroy()
	    end

     	for _, Player in Party do
		--Do whatever the RemoteEvent was supposed to do
     	end
	end
end

Players.PlayerRemoving:Connect(LeaveGame)

Let me know if it works!
I did this in a rush so it probably won’t work first try

Server script can look inside the PlayerGui, server script cannot look inside PlayerScripts, but it is generally inefficent, adding onto that, this specific piece of code won’t work, as localscripts work for only one player/client and do not replicate among other players

1 Like

if i attach the data to the host with a remote event that sends on the server before the player leaves would that help? the exploiter could still interact with the remote events right?

also im not sure how can i attach a table data to a player