Make RemoteEvents only affect the Player

Like I said I have a RemoteEvent that affects multiple objects, but I only want it to Target and Affect the Player. To give more background whenever I press a Certain button I go invisible, it will tell the server to make me invisible and it does, but it makes other models invisible too, which I don’t want. So is there a solution for this?

Can we see the code where you fire the event?

Apologies for the delayed response.

Client:

local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = script.Parent.Parent.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.Events:WaitForChild("Transparency")
local Glove = script.Parent
local isEquipped = false 
local FreddyGUI = Character.Head:WaitForChild("FreddyGUI")
local IsVisible = false

UserInputService.InputBegan:Connect(function(Input, gameProcessed)
	local KeyCode = Input.KeyCode
	if KeyCode == Enum.KeyCode.One then
		
		local goalTransparency
		if isEquipped then 
			isEquipped = false
			goalTransparency = 0
		else
			isEquipped = true
			goalTransparency = 1
		end
		
		
		RemoteEvent:FireServer(goalTransparency)
		-- After this point this is what I will see, so I will be semi transparent on my screen.
		wait(55/1000)
		
		local TTransparency
		if IsVisible then
			IsVisible = false
			TTransparency = 0
		else
			IsVisible = true
			TTransparency = 0.9
		end
		
		for _,i in pairs(Glove:GetChildren()) do
			if (i:IsA("MeshPart") or i:IsA("UnionOperation")) then
				i.Transparency = TTransparency
			end
		end
		for _,n in pairs(Character:GetChildren()) do
			if (n:IsA("MeshPart") or n:IsA("UnionOperation")) then
				n.Transparency = TTransparency
				Head.Transparency = TTransparency 
				Head.face.Transparency = TTransparency 
			end
		end
		for i,v in pairs(Character:GetChildren()) do
			if (v:IsA("Accessory")) then
				v.Handle.Transparency = TTransparency
			end
		end
	end
end)

Server:

local Player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Glove = script.Parent
local RemoteEvent = ReplicatedStorage:WaitForChild("Events"):WaitForChild("Transparency")
local Head = script.Parent.Parent.Parent:WaitForChild("Head")
local Player = game.Players.LocalPlayer
local Character = script.Parent.Parent.Parent

local function setTransparency(Player, newTransparency)
	for _,i in pairs(script.Parent:GetChildren()) do
		if (i:IsA("MeshPart") or i:IsA("UnionOperation")) then
			i.Transparency = newTransparency
		end
	end
	for _,n in pairs(script.Parent.Parent.Parent:GetChildren()) do
		if (n:IsA("MeshPart") or n:IsA("UnionOperation")) then
			n.Transparency = newTransparency
			Head.Transparency = newTransparency
			Head.face.Transparency = newTransparency
			Head.FreddyGUI.TextLabel.TextTransparency = newTransparency
		end
	end
	for i,v in pairs(script.Parent.Parent.Parent:GetChildren()) do
		if (v:IsA("Accessory")) then
			v.Handle.Transparency = newTransparency
		end
	end
end

RemoteEvent.OnServerEvent:Connect(setTransparency)

Okay first of all local Player doesnt work on the server so u could either do a for loop for the players service or u could use a player added event OR Fire the player through a remote.

I fixed that but that still doesn’t answer the question I’ve been looking for. I just want the RemoteEvent to just affect the Players and nothing else, I know it’s possible except I don’t know where to start.

Make the models invisible from the client and not from the server.

You are firing to the “Transparency” event an empty variable in your client script.

Also, in your server script, instead of doing script.parent.parent.parent to find the character, you literally have the first argument “Player” in OnServerEvent, which means you could just do Player.Character instead.

This is your server script. You should not have things like Character or Player or any variable or function that is usable by only 1 player.

The explanation to your question is somewhat confusing. If you want a remote to only affect one player or a subset of them, then the server can use FireClient on the players that should be doing work.

If what you want to achieve is to pick and choose which players receive the transparency changes, then have the client do all the rendering and don’t do any transparency setting from the server. Clients will all be responsible for visualisation.

  1. Client passes input. Tells the server that it wants the transparency changes propagated via remote, then begins modifying its own object transparency.

  2. Server receives request to propagate changes and validates the request. If the request is valid, then it uses FireClient back on the players that should see this change (excluding the player who sent the request).

  3. Other clients receive event from the server. They begin performing the transparency modifying on their end for the object.

Client → Server → Client.

1 Like