No function runs on a LocalScript no matter what I try

I’m currently having this problem where my script does not work at all whatever I try. I’ve deleted code, Changed the parent of the script, I’ve checked if anything’s delaying the script. Nothing. The Button2Down doesn’t even run as well. No errors either.

If you guys can spot what’s going on in the script i’d appreciate it.



local Player = game:GetService("Players").LocalPlayer 

local Mouse = Player:GetMouse() 
local Cam = script.Parent["UI"]["Camera UI"] --This variable gets the Cam Ui
local UserInputService = game:GetService("UserInputService") 

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Connections = {}
local Camera = workspace.Camera

Mouse.Button2Down:Connect(function() 
	print("Clicked")
	
	if Cam.Visible == true then
		Cam.Visible = false 

		for _, Connection in pairs(Connections) do
			Connection:Disconnect()
		end

		Camera.FieldOfView = 70 
		
	elseif Cam.Visible == false then
		Cam.Visible = true
		
		local fovTarget = 70
		local EaseSpeed = .2
		local scrollSpeed = 4

		local RunService = game:GetService("RunService") 

		Connections["Changed"] = UserInputService.InputChanged:Connect(function(input)
			if input.UserInputType == Enum.UserInputType.MouseWheel then
				local up = input.Position.Z < 0 and 1 or -1
				fovTarget += up * scrollSpeed
			end
		end)
		
		Connections["Heartbeat"] = RunService.Heartbeat:Connect(function()
			local fovCamera = Camera.FieldOfView
			local fovDifference = fovTarget - fovCamera
			Camera.FieldOfView += fovDifference * EaseSpeed
		end)
	end
end)

Is it a local script? If so is it in the character, StarterPlayerScripts, ReplicatedFirst, PlayerGui, or a tool? If not, it won’t run. LocalScripts only run in the 5 aforementioned locations.

Can also make it a normal script and set its RunContext (might be a different property but IIRC the property has the word “Context” in it) property to Client

Yes it’s a LocalScript and it’s parented in StarterGui but it should run, it does print things as well but the Button2Down function doesn’t seem to even be running as well as an OnClientEvent function from a RemoteEvent I had in the script

Just to be sure, you’re right clicking it right? Not left click? Any output errors?

Yes right clicking, and no there’s no errors

Turns out there was a UI covering the whole screen which was being used for a Modal.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.