Remote Event info from server to client not working

Hello Developers,

I am trying to send info from the server to the client to show the junction switches, however I cannot find a reason why it is not working, I have researched several topics and tried experimenting with several other ways but to no avail.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RE = ReplicatedStorage:WaitForChild("RemoteEvent")

script.Parent.Touched:Connect(function(touched)
	if game.Players:FindFirstChild(touched.Parent.Name) then
		local player = game.Players:FindFirstChild(touched.Parent.Name)
		RE:FireClient(player, script.Parent)
	end
end)

^ server (touch located in a model)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RE = ReplicatedStorage:WaitForChild("RemoteEvent")

RE.OnClientEvent:Connect(function(player, part)
	if part == "Touch" then
		for i,v in pairs(part:GetChildren()) do
			if v:IsA("BasePart") and v.Name == "a" then
				v.Transparency = 0
				v.CanCollide = true
			end
		end
		for i,v in pairs(part:GetChildren()) do
			if v:IsA("BasePart") and v.Name == "b" then
				v.Transparency = 0.5
				v.CanCollide = false
			end
		end
	end
end)

^ local script

robloxapp-20241016-2208508.wmv (3.2 MB)

No Errors in console.

Any help would be appreciated.
Thanks!

1 Like

I don’t think you should get the player like that
Instead check if the touched’s parent has a humanoid then get the player from the character (touched.Parent):

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RE = ReplicatedStorage:WaitForChild("RemoteEvent")

script.Parent.Touched:Connect(function(touched)
	if touched.Parent and touched.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(touched.Parent)
		RE:FireClient(player, script.Parent)
	end
end)

and for the client when you fire from server to client, you don’t need to put the player as parameter again on client, Roblox already does it for you, and you are sending the script.Parent as a part, then you are checking if it’s a string called “Touch” on client, that won’t make the condition true, I will assume you want to check the name instead:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RE = ReplicatedStorage:WaitForChild("RemoteEvent")

RE.OnClientEvent:Connect(function(part)
	if part.Name == "Touch" then
		for i,v in pairs(part:GetChildren()) do
			if v:IsA("BasePart") and v.Name == "a" then
				v.Transparency = 0
				v.CanCollide = true
			end
		end
		for i,v in pairs(part:GetChildren()) do
			if v:IsA("BasePart") and v.Name == "b" then
				v.Transparency = 0.5
				v.CanCollide = false
			end
		end
	end
end)
1 Like

As @5smokin said,

.OnClientEvent does not take in a player parameter. :FireClient only requires it so that it knows what Player should receive your data,

, which in this case is script.Parent. The correct signature is:

RE.OnClientEvent:Connect(function(part)
1 Like

Ok, so I added a print function to each scripts to check if they are function, however there is no output from them, I check if they are enabled which they are and double check the scripts.

Pretty much my changes should make the script work with no problems.

I found a solution!

Deleted current junction and copy and pasted the old one and changed the server scripts to local run (not using localscript)

image