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)
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)
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)
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.