Answered by
7 years ago Edited 7 years ago
The Event KeyDown is deprecated, so use the UserInputService instead
As for actually scripting the door, you would have to use a RemoteEvent to do that, as with Filtering Enabled on, other players won't see it. Basically, instructions are below;
Put a RemoteEvent in the ReplicatedStorage named DoorOpen
LocalScript
01 | local Player = game.Players.LocalPlayer |
02 | local userinput = game:GetService( "UserInputService" ) |
03 | local door = workspace.Door |
05 | userinput.InputBegan:Connect( function (input,processed) |
06 | if input.KeyCode = = Enum.KeyCode.E and Player.Character and Player.Character:FindFirstChild( "HumanoidRootPart" ) and not processed then |
07 | if (door.Position-Player.Character.HumanoidRootPart.Position).magnitude < 20 then |
08 | game.ReplicatedStorage:WaitForChild( "DoorOpen" ):FireServer() |
Script
01 | game.ReplicatedStorage:WaitForChild( "DoorOpen" ) |
02 | local door = workspace.Door |
04 | game.ReplicatedStorage.DoorOpen.OnServerEvent:Connect( function (player) |
The reason it didn't work is that firstly, this script, by the looks of it, wouldn't work due to the fact that a LocalScript will only work if it is in the Player's PlayerGui, Backpack, Character, PlayerScripts or ReplicatedFirst. Looking at the code, I can tell that this script is probably located in the workspace, a model in which only a server script (Script) can run in.
Even if you did change this to a server script, it still wouldn't work as LocalPlayer is only accessible to the client, and even if it worked as a Local script, Filtering Enabled will stop the client from sending the door's CFrame to the Server, and in turn stop the server from replicating that to all the other clients (players), so ultimately, you will see the change, and others won't. To stop this from happening, you'd use a RemoteEvent
When scripting though, practice makes perfect, and all this will eventually make sense.