I want to make it where, when you press a GUI TextButton this script ends.
Any ideas?
game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
game.Workspace.CurrentCamera.CFrame = game.Workspace.CameraPart.CFrame
until game.Workspace.CurrentCamera.CameraType == Enum.CameraType.Scriptable and game.Workspace.CurrentCamera.CFrame == game.Workspace.CameraPart.CFrame
while wait() do
game.Workspace.CurrentCamera.CFrame = game.Workspace.CameraPart.CFrame
end
Have a variable, clicked, set to true when clicked, and have the loop run while clicked.
Also I removed some bad practices
local camera = game:GetService("Workspace").CurrentCamera
local clicked = false
local RunService = game:GetService("RunService")
camera:GetPropertyChanged("CameraType"):Connect(function()
camera.CameraType = Enum.CameraType.Scriptable -- Don't use a loop! That is inefficient.
end)
button.Activated:Connect(function()
clicked = true
end)
while not clicked do
camera.CFrame = part.CFrame
RunService.RenderStepped:Wait()
end
RenderStepped should be used for camera stuff. In this case, before every render frame, the camera is being moved to the part, while the button is not clicked.
This code is very vague and it looks like something got cut off at the top. Anyways if you want this to “end” and have the players camera set back to normal, just do this above your while loop.
local cam = workspace.CurrentCamera
local TextButton = "Put your text button here"
TextButton.Activated:Connect(function()
cam.CameraType = "Custom"
script:Destroy()
end)
The local script I gave you should be under the text button. At the top of the script you can do local button = script.Parent to get the button relative to the script. Don’t use the code you had. It has bunch of anti-patterns.
This is the script I used (Note: This is a LocalScript in the StarterPlayerScripts.)
local camera = game:GetService("Workspace").CurrentCamera
local clicked = false
local RunService = game:GetService("RunService")
local button = game.StarterGui.TeamSelect.Frame.Advertisers
camera:GetPropertyChanged("CameraType"):Connect(function()
camera.CameraType = Enum.CameraType.Scriptable
end)
button.Activated:Connect(function()
clicked = true
end)
while not clicked do
camera.CFrame = game.Workspace.CameraPart.CFrame
RunService.RenderStepped:Wait()
end
That is your issue. You’re getting it from StarterGui.
When a player (re) spawns, StarterGui’s contents are cloned into the local player’s PlayerGui. This is false for ScreenGuis with the ResetOnSpawn property disabled.
The buttons they click, the other UI they see, the local/module scripts that run, are running inside PlayerGui.
If you move this local script inside the text button, you can do local button = script.Parent to easily get the button.
Here is the script that is inside of the CameraPart, would this be needed?
local XPos = script.Parent.Orientation.X
local ZPos = script.Parent.Orientation.Z
local Index = 0
local Speed = 0.4
while wait() do
Index = Index + 1
script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(0,math.rad(Speed),0)
script.Parent.Orientation = Vector3.new(XPos, script.Parent.Orientation.Y, ZPos)
end
Hmmm odd, according to what you said, you have to put the LocalScript as the Children of the TextButton, but what makes the actual function spin? In a simpler way of saying - It is inoperative.