How to make e to open door only happen locally

Hi I have a script here that when the player presses e, the door will open

local TweenService = game:GetService("TweenService")
local door = script.Parent.Door
local hinge = script.Parent.Hinge
local prompt = door.ProximityPrompt

local goalOpen = {}
goalOpen.CFrame = hinge.CFrame * CFrame.fromEulerAngles(0, 90, 0)

local goalClose = {}
goalClose.CFrame = hinge.CFrame * CFrame.Angles(0, 0, 0)

local tweenInfo =  TweenInfo.new(2)
local tweenOpen = TweenService:Create(hinge, tweenInfo, goalOpen)
local tweenClose = TweenService:Create(hinge, tweenInfo, goalClose)

prompt.Triggered:Connect(function()
	if prompt.ActionText == "Close" then
		tweenClose:Play()
		prompt.ActionText = "Open"
		print("Closed")
	else
		tweenOpen:Play()
		prompt.ActionText = "Close"
		print("opened")
	end
end)

I wnat to attempt to put this in a local script and make it so only the player can see their door on their screen open. How can I change this script to work like that?

4 Likes

There’s nothing in this script that is “server-exclusive” so you can probably just copy and paste your code into a new LocalScript

3 Likes

I tried that but it would not work for some reason, the door won’t open at all anymore

4 Likes

Could you send a screenshot of the uh ProximityPrompt’s hierarchy (in the Explorer)?

2 Likes

Hm nothing seems off. Maybe the adding more prints to see how far the script makes it before it halts

1 Like
print("beginning")
local TweenService = game:GetService("TweenService")
local door = game.Workspace.DoorModel.Door
local hinge = game.Workspace.DoorModel.Hinge
local prompt = door.ProximityPrompt

local goalOpen = {}
goalOpen.CFrame = hinge.CFrame * CFrame.fromEulerAngles(0, 90, 0)
print(goalOpen.CFrame)

local goalClose = {}
goalClose.CFrame = hinge.CFrame * CFrame.Angles(0, 0, 0)
print(goalClose.CFrame)

local tweenInfo =  TweenInfo.new(2)
local tweenOpen = TweenService:Create(hinge, tweenInfo, goalOpen)
local tweenClose = TweenService:Create(hinge, tweenInfo, goalClose)
print(tweenOpen)
print(tweenClose)

prompt.Triggered:Connect(function()
	print("Triggered")
	if prompt.ActionText == "Close" then
		tweenClose:Play()
		prompt.ActionText = "Open"
		print("Closed")
	else
		tweenOpen:Play()
		prompt.ActionText = "Close"
		print("opened")
	end
end)

It cannot seem to identify my door part in door model. How can I make it do that?

1 Like

If you use cframe it will still be replicated on the server, it doesn’t matter if you do it from the client, maybe you could try cloning the door from the client so that the door only exists on the client and not on the server, so would not replicate

1 Like