Hello, I have an issue with a script. I want to make a door work locally and not on the server. However, when I publish the game, if I join and press "E" on the ProximityPrompt, it doesn't work. Then, if I leave and rejoin, it works. But if I leave and rejoin again, it stops working — and so on, alternating each time. Here's the script I used:
I want the door to open only on my side with the door animation — if there’s another player, the door should not open for them.
repeat task.wait() until game:IsLoaded()
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local function waitForCharacter()
if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
return player.Character
end
return player.CharacterAdded:Wait()
end
waitForCharacter()
local door1 = workspace:WaitForChild("Door")
local door2 = workspace:WaitForChild("Door2")
assert(door1.PrimaryPart, "PrimaryPart non défini pour Door")
assert(door2.PrimaryPart, "PrimaryPart non défini pour Door2")
local hinge1 = door1.PrimaryPart
local hinge2 = door2.PrimaryPart
local promptPart = door1:FindFirstChild("Base") or door1:FindFirstChildWhichIsA("BasePart")
assert(promptPart, "Aucune base trouvée dans Door")
local prompt = promptPart:WaitForChild("ProximityPrompt")
local tweenInfo = TweenInfo.new(1)
local closedCFrame1 = hinge1.CFrame
local closedCFrame2 = hinge2.CFrame
local goalOpen1 = { CFrame = closedCFrame1 * CFrame.Angles(0, math.rad(90), 0) }
local goalClose1 = { CFrame = closedCFrame1 }
local goalOpen2 = { CFrame = closedCFrame2 * CFrame.Angles(0, math.rad(-90), 0) }
local goalClose2 = { CFrame = closedCFrame2 }
local isOpen = false
local debounce = false
prompt.ActionText = "Open"
prompt.Triggered:Connect(function()
if debounce then return end
debounce = true
prompt.Enabled = false
if isOpen then
TweenService:Create(hinge1, tweenInfo, goalClose1):Play()
TweenService:Create(hinge2, tweenInfo, goalClose2):Play()
prompt.ActionText = "Open"
else
TweenService:Create(hinge1, tweenInfo, goalOpen1):Play()
TweenService:Create(hinge2, tweenInfo, goalOpen2):Play()
prompt.ActionText = "Close"
end
isOpen = not isOpen
local sound = promptPart:FindFirstChildOfClass("Sound")
if sound then
sound:Play()
end
task.wait(1)
prompt.Enabled = true
debounce = false
end)
If someone could show me how to go about it or let me know if I made any mistakes, Thanks.