Help to open a door locally with a Remote Event [scripts + video] please

  1. What do you want to achieve? I would like to make sure that when both players touch their parts then the door opens only for those two players

  2. What is the issue? I created a remote Event to open the door as I was advised to do, but the script doesn’t work unfortunatly

  3. What solutions have you tried so far? I tried to modify the scripts, I tried to put the remote Events script locally and not locally, I tried different things without success (remote function…). (I am still a beginner)

--Local Script in StarterCharacterScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local opendoor = ReplicatedStorage:WaitForChild("opendoor2")
opendoor.OnClientEvent = function(player, part)
	game.Workspace.Door2.Transparency = 1 
end

And there is the second script

--Script in ServerScriptService
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local opendoor = ReplicatedStorage:WaitForChild("opendoor2")
local part = game.Workspace.Door2

local transparent = function()
		opendoor:FireClient(part)
end;

game.Workspace.Clef.Touched:Connect(function(hit)
 if hit.Parent.Name == "Wrench2" then
		game.Workspace.Clefv.Material = Enum.Material.Neon
		if game.Workspace.Clefv.Material == Enum.Material.Neon and game.Workspace.Clefv3.Material == Enum.Material.Neon then
			transparent()
		end
	end
end)
game.Workspace.Clef3.Touched:Connect(function(hit)
	if hit.Parent.Name == "Wrench3" then
		game.Workspace.Clefv3.Material = Enum.Material.Neon
		if game.Workspace.Clefv.Material == Enum.Material.Neon and game.Workspace.Clefv3.Material == Enum.Material.Neon then
			transparent()
		end
	end
end)

opendoor

please if someone can help me to achieve this. Thanks

FireClient requires a player instance. You should get the players somehow.

1 Like

Something like this ?

local player = game.Players:GetPlayerFromCharacter()
local transparent = function()
opendoor:FireClient(player, part)
end;

yes, now find a way to retrieve both players

If someone can go into more detail, because I can’t seem to get any benefit from their advice. Thanks
Edit: Maybe if you know a good video tutorial adapted to my subject?

Could you put some print statements around to see where you’re code is getting stuck at?

Yes i already do, the code stop working at opendoor:FireClient(part)

Like @FartFella said above, FireClient(player) has to have it’s first parameter as the player object. So you have to do

opendoor:FireClient(player, part)

But first find the player object so you can pass it through the function

Something like this ?

game.Workspace.Clef.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then 
    if hit.Parent.Name == "Wrench2" then
		game.Workspace.Clefv.Material = Enum.Material.Neon
		if game.Workspace.Clefv.Material == Enum.Material.Neon and game.Workspace.Clefv3.Material == Enum.Material.Neon then
			transparent()
			end
		end
	end
end)

it’s quite difficult for me in the sense that it’s the first time I’m trying to make a script work this way, and like everything else on roblox until you get the script right the first time then it’s not easy to understand the logic behind

Ye, here is a better indented version, and debugged

game.Workspace.Clef.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then 
        print("We have a player")
        if hit.Parent.Name == "Wrench2" then
            print("We stepped in Wrench2")
		    game.Workspace.Clefv.Material = Enum.Material.Neon
		    if game.Workspace.Clefv.Material == Enum.Material.Neon and game.Workspace.Clefv3.Material == Enum.Material.Neon then
                print("We can call the transparent function")
			    transparent()
			end
	    end
    end
end)

Thanks for ur help i really appreciated it. The script stop working after the first print “We have a player”

What’s “hit” supposed to be? And are you sure you’re referencing it correctly? You might have to do just hit.parent

because without this hit

game.Workspace.Clef.Touched:Connect(function(hit)

the script does not work anymore

This script seem’s to work :

game.Workspace.Clef.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then 
		print("We have a player")
		game.Workspace.Clef.Touched:Connect(function(hat)
		if hat.Parent.Name == "Wrench2" then
			print("We stepped in Wrench2")
			game.Workspace.Clefv.Material = Enum.Material.Neon
			if game.Workspace.Clefv.Material == Enum.Material.Neon and game.Workspace.Clefv3.Material == Enum.Material.Neon then
				print("We can call the transparent function")
				transparent()
			end
		end
	   end)
	end
end)

but now it block here

local transparent = function()
		opendoor:FireClient(part)
end;

I have an idea for the transparent function try this:

local transparent = function(player)
	opendoor:FireClient(player, part)
end;

And for the other part just do this:


game.Workspace.Clef.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then 
		print("We have a player")
		game.Workspace.Clef.Touched:Connect(function(hat)
		    if hat.Parent.Name == "Wrench2" then
			    print("We stepped in Wrench2")
			    game.Workspace.Clefv.Material = Enum.Material.Neon
			    if game.Workspace.Clefv.Material == Enum.Material.Neon and game.Workspace.Clefv3.Material == Enum.Material.Neon then
				    print("We can call the transparent function")
				    transparent(player)
			    end
	       end
	   end)
	end
end)

First you need to use touched events and debounces. Then you need to wait for 1 player to be on each part. Then you fire both those clients and use a local script with RemoteEvents.

with this doesn’t work. My remote script is

--Local Script in StarterCharacterScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local opendoor = ReplicatedStorage:WaitForChild("opendoor2")
opendoor.OnClientEvent = function(player)
	game.Workspace.Door2.Transparency = 1 
end

Does i need to change something in this ?

if i put on the other script

local transparent = function(player)
        print("open")
end;

it print “open” in the output but if i put

local transparent = function(player)
    opendoor:FireClient(player, part)
	print("hiii")
end;

then nothing happened

In theory I understood what I have to do but in practice it is more complicated.

1 Like

What is the variable part representing?

I was able to exchange with a developer who helped me but unfortunately the action is still blocked at the time of the fireclient. Here are the new scripts

--ServerScriptService
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local opendoor = ReplicatedStorage:WaitForChild("opendoor2")
local debounce = 1

local transparent = function(player)
	opendoor.FireClient(player)
end;

game.Workspace.Clef.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then 
		print("We have a player")
			if hit.Parent:FindFirstChild("Wrench2") then
			print("We stepped in Wrench2")
			game.Workspace.Clefv.Material = Enum.Material.Neon
			if game.Workspace.Clefv.Material == Enum.Material.Neon and game.Workspace.Clefv3.Material == Enum.Material.Neon then
				print("We can call the transparent function")
				transparent(player)
			end
		end
	end
end)


game.Workspace.Clef3.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then 
		print("We have a player")
		if hit.Parent:FindFirstChild("Wrench3") then
		   game.Workspace.Clefv3.Material = Enum.Material.Neon
		if game.Workspace.Clefv.Material == Enum.Material.Neon and game.Workspace.Clefv3.Material == Enum.Material.Neon then
			transparent(player)
		end
	   end
   end
end)
--LocalScript in StarterCharacter
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local opendoor = ReplicatedStorage:WaitForChild("opendoor2")

opendoor.OnClientEvent = function(player)
	game.Workspace.Door2.Transparency = 1 
end

if you have an idea what’s the problem ? Thank you