Remote Event Tween Doors Acting Weird

I’m trying to create a door with proximity prompts that tweens itself to open and close. It worked, but I decided that I would make the door move only for the client that opens it, so people don’t try to close the door on others. This is where the problem starts. After a grueling amount of testing, I managed to make the door activate on a remote event; however, when I started placing multiple doors down, the tween started to rotate the door the direction I didn’t want it to go. I did some print debugging and found out that the function (when multiple doors are present) repeats despite my script having returns.

Here’s what I’m talking about and the output for each. (--- means after one trigger)

One door:
robloxapp-20201223-1758194.wmv (700.7 KB)

---Output

Open
---
Closed
---
Open
---
Closed

Two doors:
robloxapp-20201223-1804288.wmv (2.3 MB)

---Output

Open
Closed
---
Open
Closed

Server script inside door model:

local MoveDoorEvent = game.ReplicatedStorage:WaitForChild("OpenDoor")

local db = false
local waitTime = 2

local DoorPrompt

ProximityPrompt.PromptTriggered:Connect(function(prompt,plr)
	if db == false then
		db = true
		DoorPrompt = prompt
		MoveDoorEvent:FireClient(plr,DoorPrompt)
		wait(waitTime)
		db = false
	end
end)

Local script inside StarterPlayerScripts:

local function OpenCloseDoor(object)
	local TweenService = game:GetService("TweenService")

	local hinge = object.Parent.Parent.Parent.Parent:WaitForChild("Hinge")
	
	local DoorSwingInfo = TweenInfo.new()
	local DoorSwingOpenTween = TweenService:Create(hinge,DoorSwingInfo,{
		CFrame = hinge.CFrame*CFrame.Angles(0,math.rad(130),0)
	})

	local DoorSwingCloseTween = TweenService:Create(hinge,DoorSwingInfo,{
		CFrame = hinge.CFrame*CFrame.Angles(0,math.rad(-130),0)
	})

	local DoorOpen = hinge.Parent:WaitForChild("DoorOpen")
	
	if DoorOpen.Value == true then
		DoorSwingCloseTween:Play()
		DoorOpen.Value = false
		print("Closed")
		return
	elseif DoorOpen.Value == false then
		DoorSwingOpenTween:Play()
		DoorOpen.Value = true
		print("opened")
		return
	end
end

MoveDoor.OnClientEvent:Connect(OpenCloseDoor)

What most likely happened was that the server script somehow affects both doors even though they each have their own seperate server scripts. I suspect this because while I was recording the result of placing two doors, you can see that the debounce also takes effect on the second one despite the fact that I haven’t even touched it.

I have never asked someone their opinions on the way I script. If this is bad practice, let me know.

Are remote events necessary for this? As it’s only gonna operate for one client
Also, your issue is due to the fact that both doors are hooked to the same remote event

1 Like

So there is a more effective way of doing this that doesn’t need remote events? And also, if I wanted to have multiple doors, would I need to insert seperate remote events for each door?

Yea, or pass an argument (like the proximity prompt that was used) and check if the prompt that was activated is part of the door

PromixtyPromptService.PromptTriggered also works on the client (i believe) and if so, just handle everything from there from a LocalScript

1 Like

Wow, I can’t believe I was overcomplicating the whole thing this whole time! Thanks for your answer, and I appreciate the time you took out of your day to do this. :smiley:

1 Like