What do you want to achieve? Keep it simple and clear!
I am currently working on a Train Spawner GUI. When you enter the GUI, the camera changes of Position. And if i exit the GUI, the camera needs to reset.
What is the issue? Include screenshots / videos if possible!
It resets to the player, but when i try to turn the camera, it stills stuck.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I did look, but i didn’t find anything.
I tried to change the camera type to Custom, camera subject to the player’s Humanoid and the CFrame to the Head’s CFrame
Here’s the codes i used:
-- Code that change the Camera position:
local ts = game:GetService("TweenService")
local ex = script.Parent.Frame.trainchoose.exit.ex -- my exit button variable
game.ReplicatedStorage.train.OnClientEvent:Connect(function(plr)
-- animate the rear cam
local part = workspace.spacam
local part2 = workspace.spacam2
local ti = TweenInfo.new(
10,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
-1,
true,
0
)
----------------------------------------------------------
local tw = ts:Create(part,ti,{CFrame = part2.CFrame})
tw:Play()
ex.MouseButton1Click:Connect(function() -- i didn't know how to cancel the tweening in the other script
tw:Cancel()
end)
workspace.Camera.CameraSubject = workspace.spacam
workspace.Camera.CameraType = Enum.CameraType.Scriptable
while wait() do
workspace.Camera.CFrame = part.CFrame
end
end)
-- And the code that resets the camera
script.Parent.MouseButton1Click:Connect(function(plr)
local h = game.Players.LocalPlayer.Character.Humanoid -- humanoid variable
wait(1)
workspace.Camera.CameraType = Enum.CameraType.Follow
workspace.Camera.CameraSubject = h
workspace.Camera.CFrame = h.Parent:FindFirstChild("Head").CFrame
end)
Thanks in advance if you help me!
(This is my first post so if i did something wrong, please tell me!)
Oh yeah, i just wanted to make a clear script, but here’s the full script:
local ts = game:GetService("TweenService")
local sc = script.Parent.Parent.Parent.Parent.Parent.Parent
script.Parent.MouseButton1Click:Connect(function(plr)
local h = game.Players.LocalPlayer.Character.Humanoid
-- add the bar
wait()
pcall(function()
local starterGui = game:GetService('StarterGui')
starterGui:SetCore("TopbarEnabled", true)
end)
wait()
for i,v in pairs(sc:GetChildren())do
v.Enabled = true
end
local gui = sc.trainguispa.Frame
gui:TweenPosition(UDim2.new(0,0,1,0),nil,Enum.EasingStyle.Quart,3.2)
----------------------------------------------------------
workspace.Camera.CameraType = Enum.CameraType.Custom
workspace.Camera.CameraSubject = h
local frame = gui.trainchoose
frame:TweenPosition(UDim2.new(0.196, 0, 1, 0),nil,Enum.EasingStyle.Quart,2.6)
wait(3.200001)
sc.trainguispa.Enabled = false
end)