What do you want to achieve? Keep it simple and clear!
So basically I want the player to go into View Mode when they press a key. Then click on the button to go back to Character Mode.
What is the issue? Include screenshots / videos if possible!
there is no errors in the output I have added the debounce in the script but why sometimes it doesn’t detect the debounce and the button and text is not showing?
local player = game.Players.LocalPlayer
local UserInputService = game:GetService("UserInputService")
local Cam = game.workspace:WaitForChild("Cam")
local CurrentCam = game.Workspace:WaitForChild("Camera")
local ShowCam = game.ReplicatedStorage:WaitForChild("ShowCamera")
local CamPosition = Vector3.new(31.726, 52.456, -52)
local LookAtPosition = Vector3.new(27.203, 45.491, -52)
local TextButton = script.Parent:WaitForChild("TextButton")
local TextLabel = script.Parent:WaitForChild("TextLabel")
local UpTown = game.Workspace:WaitForChild("Uptown")
local debounce = false
UserInputService.InputBegan:Connect(function(Input, chat)
if Input.KeyCode == Enum.KeyCode.C and not chat then
if debounce == false then
debounce = true
CurrentCam.CameraType = Enum.CameraType.Scriptable
CurrentCam.CFrame = CFrame.lookAt(CamPosition, LookAtPosition)
if TextLabel.Visible == false and TextButton.Visible == false then
TextLabel.Visible = true
TextButton.Visible = true
TextLabel.Text = "Current Status: View Mode"
UpTown:Play()
TextButton.MouseButton1Click:Connect(function()
CurrentCam.CameraType = Enum.CameraType.Custom
CurrentCam.CameraSubject = player.Character.Humanoid
TextLabel.Text = "Status Changed: Character Mode"
TextButton.Visible = false
UpTown:Stop()
task.wait(1.1)
TextLabel.Visible = false
end)
end
end
task.wait(5)
debounce = false
end
end)
local player = game.Players.LocalPlayer
local UserInputService = game:GetService("UserInputService")
local Cam = game.workspace:WaitForChild("Cam")
local CurrentCam = game.Workspace:WaitForChild("Camera")
local ShowCam = game.ReplicatedStorage:WaitForChild("ShowCamera")
local CamPosition = Vector3.new(31.726, 52.456, -52)
local LookAtPosition = Vector3.new(27.203, 45.491, -52)
local TextButton = script.Parent:WaitForChild("TextButton")
local TextLabel = script.Parent:WaitForChild("TextLabel")
local UpTown = game.Workspace:WaitForChild("Uptown")
local debounce = false
UserInputService.InputBegan:Connect(function(Input, chat)
if Input.KeyCode == Enum.KeyCode.C and not chat then
if debounce == false then
debounce = true
CurrentCam.CameraType = Enum.CameraType.Scriptable
CurrentCam.CFrame = CFrame.lookAt(CamPosition, LookAtPosition)
if TextLabel.Visible == false and TextButton.Visible == false then
TextLabel.Visible = true
TextButton.Visible = true
TextLabel.Text = "Current Status: View Mode"
UpTown:Play()
TextButton.MouseButton1Click:Connect(function()
CurrentCam.CameraType = Enum.CameraType.Custom
CurrentCam.CameraSubject = player.Character.Humanoid
TextLabel.Text = "Status Changed: Character Mode"
TextButton.Visible = false
UpTown:Stop()
task.wait(1.1)
TextLabel.Visible = false
end)
end
end
task.wait(5)
debounce = false
end
end)
local player = game.Players.LocalPlayer
local UserInputService = game:GetService("UserInputService")
local Cam = game.workspace:WaitForChild("Cam")
local CurrentCam = game.Workspace:WaitForChild("Camera")
local ShowCam = game.ReplicatedStorage:WaitForChild("ShowCamera")
local CamPosition = Vector3.new(31.726, 52.456, -52)
local LookAtPosition = Vector3.new(27.203, 45.491, -52)
local TextButton = script.Parent:WaitForChild("TextButton")
local TextLabel = script.Parent:WaitForChild("TextLabel")
local UpTown = game.Workspace:WaitForChild("Uptown")
local debounce = false
UserInputService.InputBegan:Connect(function(Input, chat)
if Input.KeyCode == Enum.KeyCode.C and not chat then
if debounce == false then
debounce = true
CurrentCam.CameraType = Enum.CameraType.Scriptable
CurrentCam.CFrame = CFrame.lookAt(CamPosition, LookAtPosition)
if TextLabel.Visible == false and TextButton.Visible == false then
TextLabel.Visible = true
TextButton.Visible = true
TextLabel.Text = "Current Status: View Mode"
UpTown:Play()
TextButton.MouseButton1Click:Wait()
CurrentCam.CameraType = Enum.CameraType.Custom
CurrentCam.CameraSubject = player.Character.Humanoid
TextLabel.Text = "Status Changed: Character Mode"
TextButton.Visible = false
UpTown:Stop()
task.wait(1.1)
TextLabel.Visible = false
end
end
task.wait(5)
debounce = false
end
end)
are you using this on a script? because when the text button gets clicked, only local scripts can detect when the text button is clicked , so you might need to use a remote event
When you connect an event it will still connected until you disconnect it or until an if statement prevents it to run their function, so they willl still be able to click it, since the debounce is not inside the MouseButton1Click function.