Proximity based doors, overlapping when opened or closed

Run down...

Hey, so I made these doors react to the proximity of the player, when they are in a range of 15 studs or so, they swing open. However, I have one underlying issue.

My Set up:

My doors react so that they are rotated on a hinge, by a factor of `math.rad(90)` across the y axis (a simple rotation). However, this occurs only on the client side and I want to expand it over to the server so other player who are further away can see the doors open for the player closest to it.

The reason I made this in the client side was so it does not hinder performance on the server side, where all the doors constantly loop over to find the closest player, of which would further degrade when they are more players. Instead, the doors open in the server side via an event that is called, where they copy the translation that occurred in the client side (but omits it for the specific client).

This obviously poses an issue, when more players are near the door, it copies the position that it was previously or from what was previously called,
image
Looks something like this

How could I avoid this? (Basic psuedocode or just planning run down can help, you can also tell me if the very basis from where my script is originating is flawed)

Thank you!

Could you please show me the code and explorer objects for the doors?

It’s literally a whole system, however, I can show the snippet for how the door rotates and how it replicates over to the server (note, this is not the full code at all)

Local Script:

function triggerMediumProximity(medium, originalOrientation)
	if medium.Name == "Door_" then
		
		local doorHinge = medium.ClosedVariant.PrimaryPart
		local doorState = doorHinge.DoorState
		local tweenState = doorHinge.TweenState
		
		local glowPart = medium.OpenVariant.HolyEntrance
		
		if (humanoidRootPart.Position - doorHinge.Position).Magnitude <= 30 then			
			if doorState.Value == "closed" and tweenState.Value == "idle" then
				
				doorState.Value = "open"

				local goal = {}
				goal.CFrame = doorHinge.CFrame * CFrame.Angles(0, math.rad(90), 0)

				local holyEntranceGoal = {}
				holyEntranceGoal.Transparency = 0

				local openAnimateTween = TweenService:Create(doorHinge, moveDoorAnimateTweenInfo, goal)
				local openAnimateGlowTween = TweenService:Create(glowPart, moveDoorAnimateTweenInfo, holyEntranceGoal) 
				
				openAnimateTween:Play()
				tweenState.Value = "playing"
				task.wait(0.08)
				openAnimateGlowTween:Play()
				
				proximityResponseEvent:FireServer(medium, "open")
				
				openAnimateTween.Completed:Connect(function()
					tweenState.Value = "idle"
				end)
			end
			
		elseif (humanoidRootPart.Position - doorHinge.Position).Magnitude > 30 then 
			if doorState.Value == "open" and tweenState.Value == "idle" then
				
				doorState.Value = "closed"

				local goal = {}
				goal.CFrame = doorHinge.CFrame * CFrame.Angles(0, math.rad(-90), 0)

				local holyEntranceGoal = {}
				holyEntranceGoal.Transparency = 1

				local closeAnimateTween = TweenService:Create(doorHinge, moveDoorAnimateTweenInfo, goal)
				local closeAnimateGlowTween = TweenService:Create(glowPart, moveDoorAnimateTweenInfo, holyEntranceGoal)
				
				closeAnimateTween:Play()
				tweenState.Value = "playing"
				task.wait(0.08)
				closeAnimateGlowTween:Play()
				
				proximityResponseEvent:FireServer(medium, "close")
				
				closeAnimateTween.Completed:Connect(function()
					tweenState.Value = "idle"
				end)
			end
		end
	end

Server Script

mediumProximityEvent.OnServerEvent:Connect(function(player, medium, arg)
	print(player, medium, arg)

	if medium.Name == "Door_" then
		print("Open fired")

		local doorHinge = medium.ClosedVariant.DoorPivot
		local glowPart = medium.OpenVariant.HolyEntrance

		if arg == "open" then 
			local goal = {}
			goal.CFrame = doorHinge.CFrame * CFrame.Angles(0, math.rad(90), 0)

			local holyEntranceGoal = {}
			holyEntranceGoal.Transparency = 0

			local openAnimateTween = TweenService:Create(doorHinge, moveDoorAnimateTweenInfo, goal)
			local openAnimateGlowTween = TweenService:Create(glowPart, moveDoorAnimateTweenInfo, holyEntranceGoal) 

			openAnimateTween:Play()
			task.wait(0.08)
			openAnimateGlowTween:Play()

			local openingAudio = SoundService.LevelEntranceSystemAudio.DoorOpen:Clone()
			openingAudio.Parent = doorHinge
			openingAudio:Play()

			openingAudio.Ended:Connect(function() openingAudio:Destroy() end)

		elseif arg == "close" then 
			local goal = {}
			goal.CFrame = doorHinge.CFrame * CFrame.Angles(0, math.rad(-90), 0)

			local holyEntranceGoal = {}
			holyEntranceGoal.Transparency = 1

			local openAnimateTween = TweenService:Create(doorHinge, moveDoorAnimateTweenInfo, goal)
			local openAnimateGlowTween = TweenService:Create(glowPart, moveDoorAnimateTweenInfo, holyEntranceGoal) 

			openAnimateTween:Play()
			task.wait(0.08)
			openAnimateGlowTween:Play()

			local closingAudio = SoundService.LevelEntranceSystemAudio.DoorClose:Clone()
			closingAudio.Parent = doorHinge
			closingAudio:Play()

			closingAudio.Ended:Connect(function() closingAudio:Destroy() end)
		end
	end
end)

It clicked me, I perhaps could just do the translations only in the server side as they would anyways replicate to the client, and checking it is in motion and all that can be very easy to do just only once in the server. Never mind lads.

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