I already searched about this problem but I can’t find any topic that similar. Any help is appriciated . Here is the script:
local door1 = script.Parent.Left
local door2 = script.Parent.Right
local bil = script.Parent.Tiag.BillboardGui
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local cam = workspace.CurrentCamera
local cutscenecam = workspace.Cutscene.CutsceneCam
local TS = game:GetService("TweenService")
local UIS = game:GetService("UserInputService")
local ti = TweenInfo.new(2)
local goal = {}
goal.CFrame = cutscenecam.CFrame * CFrame.new(502.1, -346.6, -86.1)
UIS.InputBegan:Connect(function(input , gameprocess)
if gameprocess then return end
if input.KeyCode == Enum.KeyCode.E then
if (character.HumanoidRootPart.Position - door1.Position).Magnitude < 5 then
cam.CameraType = Enum.CameraType.Scriptable
cam.CFrame = cutscenecam.CFrame
TS:Create(cutscenecam , ti , goal)
end
end
end)
Yep, although if you’re going on workspace for it, I highly suggest not doing it as other people will not be able to see, but you can check up on tutorials on how to tween it.
You can’t get the local player in a server script. It is in the name, local. TweenService works on local scripts too and you might want to change your script to local script.
Solution is basic, just change script local script and don’t forget that local scripts don’t run on workspace. Put it inside StarterCharacterScripts or StarterPlayerScripts.
Firstly, UserInputService is client-side only, so it cannot be used within a server script, consider replacing this with a ClickDetector, as you’d also be able to get the player from the function of when the door is clicked. This also solves your problem of attempting to get the player and character, as I assume many people have already told you, game.Players.LocalPlayer will not retrieve the player within a server script, however the ClickDetector’s function, ClickDetector.MouseClick, is able to retrieve the player through the following:
ClickDetector.MouseClick:Connect(function(player)
-- your code
end)
You’d probably want to use RemoteEvents to send the LocalPlayer variable to the server, then calculate the magnitude of the player (HumanoidRootPart) and the door on a server script in order to handle opening and closing it.