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.