Remote Event for door system not actually firing to all clients

Pretty much what the title says, I believe what I have is, if a proximity prompt named DoorPrompt gets triggered, it fires a remote event from the server to a script in StarterPlayerScripts (for all clients) to open the door for everyone (in a previous post I mentioned handling tween is better on the client side, so I did just that). However, the door only opens for the player that opened said door, not for others.

Another thing that happens is that, if there is more than one door, opening any door will open a random door out of all of them, which is less than ideal.

DoorHandler script in ServerScriptStorage:

local PPS, TS, RS = game:GetService("ProximityPromptService"), game:GetService("TweenService"), game:GetService("ReplicatedStorage")
local DoorEvent = RS:WaitForChild("DoorEvent")

function PromptTriggered(Prompt)
	if Prompt.Name == "DoorPrompt" then
		DoorEvent:FireAllClients()
	end
end

PPS.PromptTriggered:Connect(PromptTriggered)

SPSDoorPrompt local script in StarterPlayerScripts:

local PPS, TS, RS, SSS = game:GetService("ProximityPromptService"), game:GetService("TweenService"), game:GetService("ReplicatedStorage"), game:GetService("ServerScriptService")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Debounce = false

RS.DoorEvent.OnClientEvent:Connect(function(Prompt)
	local Prompt = game.Workspace.Door.Center.DoorPrompt
	local Hinge = Prompt.Parent.Parent.Hinge
	local Door = Prompt.Parent

	local Open = {}
	Open.CFrame = Hinge.CFrame * CFrame.Angles(0, math.rad(90), 0)
	local Close = {}
	Close.CFrame = Hinge.CFrame * CFrame.Angles(0, math.rad(-90), 0)

	local DoorTweenInfo = TweenInfo.new(1.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
	local OpenTween = TS:Create(Hinge, DoorTweenInfo, Open)
	local CloseTween = TS:Create(Hinge, DoorTweenInfo, Close)

	local function isPositionInFront(position)
		return (Door.Position - position).Unit:Dot(Door.CFrame.LookVector) > 0
	end

	if Debounce then return end
	Debounce = true
	if Prompt.ActionText == "Open" then
		OpenTween:Play()
		Prompt.ActionText = "Close"
	else
		CloseTween:Play()
		Prompt.ActionText = "Open"
	end
	task.wait(1.5)
	Debounce = false
end)

function PromptHoldFillBegan(Prompt)
	if Prompt.Name == "DoorPrompt" then
		for i, v in ipairs(Prompt.Parent:GetChildren()) do
			if v:IsA("SurfaceGui") then
				local Fill = v.Main.Fill
				local FillTween = TS:Create(Fill, TweenInfo.new(Prompt.HoldDuration), { Size = UDim2.fromScale(1, 1)})
				FillTween:Play()
				local function PromptHoldFillEnded(Prompt)
					FillTween:Cancel()
					local UnfillTween = TS:Create(Fill, TweenInfo.new(0.2), { Size = UDim2.fromScale(1, 0)})
					UnfillTween:Play()
				end
				PPS.PromptButtonHoldEnded:Connect(PromptHoldFillEnded)
			end
		end
	end
end

function PromptShown(Prompt)
	if Prompt.Name == "DoorPrompt" then
		for i, v in ipairs(Prompt.Parent:GetChildren()) do
			if v:IsA("SurfaceGui") then
				local UIStrokeTween = TS:Create(v.Main.UIStroke, TweenInfo.new(0.5), { Transparency = 0})
				UIStrokeTween:Play()
				local ButtonTween = TS:Create(v.Main.Button, TweenInfo.new(0.5), { TextTransparency = 0})
				ButtonTween:Play()
			end
		end
	end
end

function PromptHidden(Prompt)
	if Prompt.Name == "DoorPrompt" then
		for i, v in ipairs(Prompt.Parent:GetChildren()) do
			if v:IsA("SurfaceGui") then
				local UIStrokeTween = TS:Create(v.Main.UIStroke, TweenInfo.new(0.5), { Transparency = 1})
				UIStrokeTween:Play()
				local ButtonTween = TS:Create(v.Main.Button, TweenInfo.new(0.5), { TextTransparency = 1})
				ButtonTween:Play()
			end
		end
	end
end

PPS.PromptShown:Connect(PromptShown)
PPS.PromptHidden:Connect(PromptHidden)
PPS.PromptButtonHoldBegan:Connect(PromptHoldFillBegan)
PPS.PromptButtonHoldEnded:Connect(PromptHidden)

Door structure (the only thing that will change when I get this to work is the amount of parts a given door contains):

Apologies for no comments in the scripts.

1 Like

This should be done on the server. If a player joins after someone opened the door, the door will be closed for them.

Well, it should be rendered on the client, but after 1.5 seconds the door should just CFrame open or closed.

I just tried this, but it doesn’t seem to be working. The door seems to close itself right after it finishes opening, and I can see that it’s now the server showing the tween, not the client.

You really do not have to FireAllClient from the server. Whatever happens from server will also happen inside local. Basically, if the server open Door #1, the door will be open already for all clients. You can let only one person open the door and send a remote event to the server to open that door. Other players will see that door open also.

This is what I had before, but isn’t tweening from the server choppy? Atleast, that’s what it looks like to me when I compare the door opening then and now

Ah, I get it, smooth opening is what you want. For solving random door is being opened. You can try adding one more parameter from server telling specifically which door is being opened. Have you tried this one out already?

Well, I have tried, yeah, but so far nothing I’ve tried is working. I honestly don’t quite know what I’m doing. I think when the door opening/closing was in a script in ServerScriptStorage, then it knew which door to trigger because I was using PromptTriggered? Maybe? But now that it’s not there, I have no clue.

Disregard that, I believe I have fixed all my issues? Just checked, and the door opens for all clients (but not the server yet, still working on that), and every door appears to be independent. Hurray!

I simply forgot to add Prompt in FireAllClients(), like so:

function PromptTriggered(Prompt)
	if Prompt.Name == "DoorPrompt" then
		DoorEvent:FireAllClients(Prompt)
	end
end

Weird, because you define it there.

It is wierd yeah, but everything seems to be working:


The only thing I have left to do is, as you mentioned, open the door for the server

Sorry to bother you after I already marked a solution, but how can I make it so that the door instantly opens for the server, but regularly on the client? If I try to do what you mentioned here, whether it’s before or after the remote event, the door opens instantly (along with other oddities, such as the door rotating way beyond what it’s supposed to) for both. The server door opening/closing, if you will, kinda overrides the client one, if that makes sense

Yeah, I’m not completely sure. You can try parenting the door to nil on the client and then back to its original parent, which might stop replication.

1 Like

Here’s what I’m trying so far (not working unfortunately)

Server script:

local PPS, RS = game:GetService("ProximityPromptService"), game:GetService("ReplicatedStorage")
local DoorEvent = RS:WaitForChild("DoorEvent")

function PromptTriggered(Prompt)
	if Prompt.Name == "DoorPrompt" then
		local Pivot = Prompt.Parent.Parent.Pivot
		
		if Prompt.ActionText == "Open" then
			Pivot.CFrame = Pivot.CFrame * CFrame.Angles(0, math.rad(100), 0)
		else
			Pivot.CFrame = Pivot.CFrame * CFrame.Angles(0, math.rad(-100), 0)
		end
		DoorEvent:FireAllClients(Prompt)
	end
end

PPS.PromptTriggered:Connect(PromptTriggered)

Local script in SPS (only a snippet though):

if Debounce then return end
Debounce = true
if Prompt.ActionText == "Open" then
	Pivot.Parent = nil
	Prompt.Enabled = false
	OpenTween:Play()
	Prompt.ActionText = "Close"
	Pivot.Parent = Prompt.Parent.Parent
else
	Pivot.Parent = nil
	Prompt.Enabled = false
	CloseTween:Play()
	Prompt.ActionText = "Open"
	Pivot.Parent = Prompt.Parent.Parent
end
task.wait(1.5)
Prompt.Enabled = true
Debounce = false

I’ve renamed the Hinge to Pivot, set the angle to 100* and removed Door since I didn’t actually use it anywhere, anyway here’s what happens:


Maybe I should just make another topic

Oh, the answer is simple. Just wait a second before changing the CFrame to let the tween on the client to complete. This is, of course, after firing the event to all clients.

If this doesn’t help, it’s probably better to make another topic.

Tried this, and while it looks fine on the client (except the fact that I now see a single frame of the door flashing open), I switch to the server and the door, when closed again on the client, is very much at a wierd angle for the server. Time to cook up a new topic, thanks for the help

Wait, before you do that, you might want to change the prompt’s text on the server as well.


Huh, I guess it worked. It’s always the simplest things. Only thing that’s bothering me now is the door flashing briefly, but oh well. Gonna put this topic to rest now and again, thanks so much
EDIT: Removing the ‘Pivot.Parent = nil’ and ‘Pivot.Parent = Prompt.Parent.Parent’ lines eliminated that flash. It’s finally over

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.