Hi,
The idea of this project I’m making is that when you touch this circle it moves your Camera to another part called Camera inside of a garage I built and there you can choose what car you buy. Like this from the game Driving Empire:
And this is a picture of the location and some stats of the Camera Part:
I have tried looking for solutions on the internet but could not find many helpful and I do not have much scripting experience in fact I am still learning so could someone please help. (also if possible could it be so that it does not teleport the camera there instead it just moves it).
Thanks
Although would this make it to that when the character touches the part it moves the Camera to a different spot? Also my scripting knowledge is very low and I am rather learning Lua so I don’t know what Tweens are or how to make a script.
Before learning all of this, I would advise learning the basics of lua. Also, I did not realize that this was deprecated.
So as @1000knives said, you probably want to use TweenService:
This is the script I put I think it should match what you said.
But it still does not work. Am I doing something wrong?
Camera.CameraType = “Scriptable”
As @ RichardPRoosevelt said you need to use a localscript here if you are changing the camera. You can’t change camera from a server script
So you need to create a local script and put it somewhere that will run, put it in starterplayerscripts for example
Start off doing stuff simple, so first step, make it so that the camera just changes. Once you’ve got that working then add in fancier stuff like making it move smoothly, always easier to do things one little step at a time
So the script should be something like. Note if you are scripting stuff it makes it easier to not have spaces in the part names, so I’d suggest change the name of the part to TouchToBuyPart not “Touch To buy Part”
local part = game.Workspace.TouchToBuyPart
local camera = game.Workspace.CurrentCamera
part.Touched:Connect(function()
camera.CameraType = Enum.CameraType.Scriptable
-- Change the numbers here to be the position you want the camera to be in
camera.CFrame = CFrame.new(50, 10, 50)
end)
This isn’t going to be the finished script yet, but should get the start of it working
OK the animation is fairly easy to add in, you do want to use TweenService for that
local TweenService = game:GetService("TweenService")
local part = game.Workspace.TouchToBuyPart
local camera = game.Workspace.CurrentCamera
part.Touched:Connect(function(hit)
-- Touched can get triggered lots of times, so check here if the camera is already scriptable, only do stuff if its not
if camera.CameraType ~= Enum.CameraType.Scriptable then
camera.CameraType = Enum.CameraType.Scriptable
local targetPosition = Vector3.new(50, 10, 50) -- put the position of where you want the camera to be here
local targetLookAt = Vector.new(60, 5, 50) -- put where you want the camera to look at here
local targetCFrame = CFrame.new(targetPosition, targetLookAt)
local tweenInfo = TweenInfo.new(1) -- animation lasts 1 second
local goal = {}
goal.CFrame = targetCFrame
local tween = TweenService:Create(camera, tweenInfo, goal)
tween:Play()
-- I'd also just move the player a bit so that they are no longer touching the part, otherwise when they go back from the shop they might end up getting teleported straight back when they move, which is annoying.
hit.Parent:SetPrimaryPartCFrame(hit.Parent.PrimaryPart.CFrame + Vector3.new(-5, 0, 0))
end
end)
Somewhere you’re going to need a GUI button in your shop to exit and go back to normal, when you have that when it’s clicked you should just need to do
local camera = game.Workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Custom
Ok, I put that code inside of the same script as the one used to teleport the camera it still does teleport the camera just that it does not smoothly move it, it is the same as before. I might have done something wrong I think.
local part = game.Workspace.TouchToBuyPart
local camera = game.Workspace.CurrentCamera
part.Touched:Connect(function()
camera.CameraType = Enum.CameraType.Scriptable
– Change the numbers here to be the position you want the camera to be in
camera.CFrame = CFrame.new(-63.778, 8.25, 46.251)
local TweenService = game:GetService("TweenService")
local part = game.Workspace.TouchToBuyPart
local camera = game.Workspace.CurrentCamera
part.Touched:Connect(function(hit)
-- Touched can get triggered lots of times, so check here if the camera is already scriptable, only do stuff if its not
if camera.CameraType ~= Enum.CameraType.Scriptable then
camera.CameraType = Enum.CameraType.Scriptable
local targetPosition = Vector3.new(-63.778, 8.25, 46.251) -- put the position of where you want the camera to be here
local targetLookAt = Vector.new(-66.307, 5.447, 19.599) -- put where you want the camera to look at here
local targetCFrame = CFrame.new(targetPosition, targetLookAt)
local tweenInfo = TweenInfo.new(3) -- animation lasts 1 second
local goal = {}
goal.CFrame = targetCFrame
local tween = TweenService:Create(camera, tweenInfo, goal)
tween:Play()
-- I'd also just move the player a bit so that they are no longer touching the part, otherwise when they go back from the shop they might end up getting teleported straight back when they move, which is annoying.
hit.Parent:SetPrimaryPartCFrame(hit.Parent.PrimaryPart.CFrame + Vector3.new(-5, 0, 0))
end
end)
end)
Is this correct?
also thank you for the thing about resetting the Camera it is just what I needed.
Just to double check, make sure that you don’t have this in the script anywhere, so if that’s there take it out and just have the code that’s doing the movement by tween?
It should all be smooth then.
So the code in the script should I think be just this; nothing else
local TweenService = game:GetService("TweenService")
local part = game.Workspace.TouchToBuyPart
local camera = game.Workspace.CurrentCamera
part.Touched:Connect(function(hit)
-- Touched can get triggered lots of times, so check here if the camera is already scriptable, only do stuff if its not
if camera.CameraType ~= Enum.CameraType.Scriptable then
camera.CameraType = Enum.CameraType.Scriptable
local targetPosition = Vector3.new(-63.778, 8.25, 46.251) -- put the position of where you want the camera to be here
local targetLookAt = Vector.new(-66.307, 5.447, 19.599) -- put where you want the camera to look at here
local targetCFrame = CFrame.new(targetPosition, targetLookAt)
local tweenInfo = TweenInfo.new(3) -- animation lasts 1 second
local goal = {}
goal.CFrame = targetCFrame
local tween = TweenService:Create(camera, tweenInfo, goal)
tween:Play()
-- I'd also just move the player a bit so that they are no longer touching the part, otherwise when they go back from the shop they might end up getting teleported straight back when they move, which is annoying.
hit.Parent:SetPrimaryPartCFrame(hit.Parent.PrimaryPart.CFrame + Vector3.new(-5, 0, 0))
end
end)