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 return
s.
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.