So what I’m making is a store,and once you get close to the cashier and a proximity prompt will pop up,once you hold E for a second it will activate a camera tween that will focus the camera on the desk where the cashier is at,once the camera changes you can use the same prompt to return the camera back to normal (This works with a boolean,for example if the boolean is true and you hold E the prompt will turn it to false and vice versa).
However, the default camera that I have for my game is a top-down camera type so when I test my game and I hold E after the camera tween the camera stays in the same position and does’nt turn back to the defailt one.
Also some other scripts that I made with this prompt works fine,stuff like a black screen popping up each time the prompt is triggered,the player being unable to walk,some gui popping up or disappearing when holding E and reappearing or disappearing when holding E again.
This is the top-down view camera script.
wait(1)
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local humRp = char:WaitForChild("HumanoidRootPart")
local Cam = workspace.CurrentCamera
Cam.CameraType = Enum.CameraType.Scriptable
local speed = 1.5
local studOffset = 35
local lastDelta = 0
game["Run Service"].RenderStepped:Connect(function(dt)
dt = (lastDelta + dt)/2 -- makes delta time smoooth
lastDelta = dt
Cam.CFrame = Cam.CFrame:Lerp( CFrame.new(humRp.Position.X,humRp.Position.Y + studOffset,humRp.Position.Z) * CFrame.Angles(math.rad(-90),0,0) , dt * speed)
end)
Cam.FieldOfView = 90
-------------------------------------------------------------------------
local prompt = game.Workspace["Gun NPC"].GunStorePrompt
local promptboolean = false
prompt.Triggered:Connect(function()
if promptboolean == false then
promptboolean = true
wait(2) --The wait(2) is there because that's the duration of the balck screen
script.Disabled = true
elseif promptboolean == true then
promptboolean = false
wait(2)
script.Disabled = false
end
end)
This is the camera tween script.
wait(1)
--------------------------------------Making the Tween----------------------------------
local ts = game:GetService("TweenService")
local finish = game.Workspace.GSCamPart1 or game.Workspace:FindFirstChild("GSCamPart1") or game.Workspace:WaitForChild("GSCamPart1")
local lookAt = game.Workspace.FocusPart or game.Workspace:FindFirstChild("FocusPart")
local info = TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0)
local goal = {}
goal.CFrame = CFrame.new(finish.Position, lookAt.Position)
local Cam = workspace.CurrentCamera
local tween = ts:Create(Cam, info, goal)
----------------------------------------------------------------------------------------
local prompt = game.Workspace["Gun NPC"].GunStorePrompt
local promptboolean = false --Boolean
prompt.Triggered:Connect(function()
if promptboolean == false then
promptboolean = true
wait(2)
Cam.CameraType = Enum.CameraType.Scriptable
tween:Play()
tween.Completed:Connect(function()
task.wait(1000000000000)
end)
elseif promptboolean == true then
promptboolean = false
wait(2.1)
tween:Cancel()
end
end)