Function override by an input?

Hello, I have a problem encountering and don’t have any solutions anymore to fix this.

(What I wanted to do)
I wanted to try creating a gun in a way which I create the main functions from a module, and then calling it from the Local Script.

(The issue I am encountering)

function gunModule.Scoping(enable)
	if enable == true then
		if gunModule.state.Disable then return end
		gunModule.scopeState.scopeIdleAnim:Play()
		gunModule.scopeState.IsScoping = true
		gunModule.plrObject.hum.CameraOffset = Vector3.new(3,0,0)
		gunModule.plrObject.hum.UseJumpPower = true
		gunModule.plrObject.hum.JumpPower = 0
		gunModule.plrObject.hum.AutoRotate = false
		gunModule.plrObject.Plr.CameraMaxZoomDistance = 5.5
		gunModule.plrObject.Plr.CameraMinZoomDistance = 5.5
		uis.MouseIconEnabled = true
		gunModule.state.playerMouse.Icon = "http://www.roblox.com/asset/?id=15722065980"
		local property = {}
		property.FieldOfView = 50
		local scopeTween = TS:Create(gunModule.plrObject.camera, TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.In), property)
		scopeTween:Play()
		runService:BindToRenderStep("Scoping", Enum.RenderPriority.Camera.Value + 1, function()
			uis.MouseBehavior = Enum.MouseBehavior.LockCenter 
			local _, y = gunModule.plrObject.camera.CFrame.Rotation:ToEulerAnglesYXZ() 
			TS:Create(gunModule.plrObject.hrp, TweenInfo.new(0.05, Enum.EasingStyle.Linear, Enum.EasingDirection.In), {CFrame = CFrame.new(gunModule.plrObject.hrp.Position) * CFrame.Angles(0,y,0)}):Play()
		end)
	else
		gunModule.scopeState.scopeIdleAnim:Stop()
		gunModule.scopeState.IsScoping = false
		gunModule.plrObject.hum.JumpPower = 50
		gunModule.plrObject.hum.UseJumpPower = false
		gunModule.plrObject.hum.CameraOffset = Vector3.new(0, 0, 0)
		runService:UnbindFromRenderStep("Scoping")
		uis.MouseIconEnabled = false
		--gunModule.state.playerMouse.Icon = ""
		gunModule.plrObject.hum.AutoRotate = true
		gunModule.plrObject.Plr.CameraMaxZoomDistance = 128
		gunModule.plrObject.Plr.CameraMinZoomDistance = 0.5
		local resetTween = TS:Create(gunModule.plrObject.camera, TweenInfo.new(0.3, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {FieldOfView = 70})
		resetTween:Play()
	end
end

This function although when the disable isn’t called nor it is made to stop at a certain limit of time, it seems that the function doesn’t work as it intended.

I want it to keep the camera to its side, even while moving, this is what I wanted that function to do.

When the function is called, it works fine that is if that player does not perform any input (keyboards, mouse moving etc) PS: excluding its activation call

When I print the MouseBehavior, it stays still at “Enum.MouseBehavior.LockCenter”, and If i perform a movement or an input, the mouse behavior changes to “Enum.MouseBehavior.LockCurrentPosition”

I also tried forcefully placing it into another loop to check if mouse behavior is not lock center and then forcing it to stay at lock center, but it is still overriden by the input somehow.

Here is a video of the issue:

As I stay still while activating the scope, it works fine, however If I made an input such as pressing keys, the function stops working as I have intended for it to do.

The scoping isn’t even disabled or even called to be disabled unless a player releases its activation key. What is the problem? Is there a way to fix this?

Here is my entire module script

local gunModule = {}
local uis = game:GetService("UserInputService")
local runService = game:GetService("RunService")
local TS = game:GetService("TweenService")



gunModule.state = {}
gunModule.plrObject = {}
gunModule.rollingConfig = {}
gunModule.MobileUI = {}
gunModule.gunConfig = {}
gunModule.gunEvents = {}
gunModule.scopeState = {}

local function loadData()
	gunModule.state.playerMouse = nil
	gunModule.state.ExpectingInput = false
	gunModule.state.isMouse1down = false
	gunModule.state.isMouse2down = false
	gunModule.state.Disable = false
	
	gunModule.plrObject.Plr = nil
	gunModule.plrObject.PlrGui = nil
	gunModule.plrObject.char = nil
	gunModule.plrObject.hum = nil
	gunModule.plrObject.hrp = nil
	gunModule.plrObject.camera = nil


	gunModule.rollingConfig.isRolling = false
	gunModule.rollingConfig.canRoll = false
	gunModule.rollingConfig.rollSpeed = false
	gunModule.rollingConfig.rollDuration = false
	gunModule.rollingConfig.rollAnim = nil
	gunModule.rollingConfig.rollCooldown = 2


	gunModule.MobileUI.mobileAssistant = nil
	gunModule.MobileUI.crossHairMobile = nil
	gunModule.MobileUI.reloadMobile = nil
	gunModule.MobileUI.FireMobile = nil
	gunModule.MobileUI.rollMobile = nil
	gunModule.MobileUI.sprintMobile = nil


	gunModule.gunConfig.GunUI = nil
	gunModule.gunConfig.isReloading = nil
	gunModule.gunConfig.maxBullet = nil
	gunModule.gunConfig.currentBullet = nil
	gunModule.gunConfig.isFiring = false
	gunModule.gunConfig.gunCooldown = nil


	gunModule.gunEvents.sprintEvent = nil
	gunModule.gunEvents.firingEvent = nil


	gunModule.scopeState.scopeIdleAnim = nil
	gunModule.scopeState.IsScoping = false
end

loadData()
local rollMovementControl

function gunModule.Scoping(enable)
	if enable == true then
		if gunModule.state.Disable then return end
		gunModule.scopeState.scopeIdleAnim:Play()
		gunModule.scopeState.IsScoping = true
		gunModule.plrObject.hum.CameraOffset = Vector3.new(3,0,0)
		gunModule.plrObject.hum.UseJumpPower = true
		gunModule.plrObject.hum.JumpPower = 0
		gunModule.plrObject.hum.AutoRotate = false
		gunModule.plrObject.Plr.CameraMaxZoomDistance = 5.5
		gunModule.plrObject.Plr.CameraMinZoomDistance = 5.5
		uis.MouseIconEnabled = true
		gunModule.state.playerMouse.Icon = "http://www.roblox.com/asset/?id=15722065980"
		local property = {}
		property.FieldOfView = 50
		local scopeTween = TS:Create(gunModule.plrObject.camera, TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.In), property)
		scopeTween:Play()
		runService:BindToRenderStep("Scoping", Enum.RenderPriority.Camera.Value + 1, function()
			uis.MouseBehavior = Enum.MouseBehavior.LockCenter 
			local _, y = gunModule.plrObject.camera.CFrame.Rotation:ToEulerAnglesYXZ() 
			TS:Create(gunModule.plrObject.hrp, TweenInfo.new(0.05, Enum.EasingStyle.Linear, Enum.EasingDirection.In), {CFrame = CFrame.new(gunModule.plrObject.hrp.Position) * CFrame.Angles(0,y,0)}):Play()
		end)
	else
		gunModule.scopeState.scopeIdleAnim:Stop()
		gunModule.scopeState.IsScoping = false
		gunModule.plrObject.hum.JumpPower = 50
		gunModule.plrObject.hum.UseJumpPower = false
		gunModule.plrObject.hum.CameraOffset = Vector3.new(0, 0, 0)
		runService:UnbindFromRenderStep("Scoping")
		uis.MouseIconEnabled = false
		--gunModule.state.playerMouse.Icon = ""
		gunModule.plrObject.hum.AutoRotate = true
		gunModule.plrObject.Plr.CameraMaxZoomDistance = 128
		gunModule.plrObject.Plr.CameraMinZoomDistance = 0.5
		local resetTween = TS:Create(gunModule.plrObject.camera, TweenInfo.new(0.3, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {FieldOfView = 70})
		resetTween:Play()
	end
end


function gunModule.UIHandler()
	if not gunModule.plrObject.Plr then return end
	if not gunModule.plrObject.PlrGui:FindFirstChild(gunModule.gunConfig.GunUI.Name) then
		local clUI = gunModule.gunConfig.GunUI:Clone()
		clUI.Parent = gunModule.plrObject.PlrGui
		gunModule.MobileUI.crossHairMobile.Visible = true
		gunModule.MobileUI.reloadMobile.Visible = true
		gunModule.MobileUI.FireMobile.Visible = true
		gunModule.MobileUI.rollMobile.Visible = true
		mm = gunModule.MobileUI.reloadMobile.InputBegan:Connect(function(input, isTyping)
			if isTyping then return end
			if input.UserInputType == Enum.UserInputType.Touch then
				if gunModule.gunConfig.isReloading.Value == false then
					gunModule.gunEvents.firingEvent:FireServer(nil,true)
				end
			end
		end)
		local ammoLabel = clUI:WaitForChild("Ammo")
		local reloadingLabel = ammoLabel:WaitForChild("Reloading")
		ammoLabel.Text = gunModule.gunConfig.currentBullet.Value.."/"..gunModule.gunConfig.maxBullet.Value

		gunModule.gunConfig.isReloading.Changed:Connect(function(val)
			if val == true then
				reloadingLabel.Visible = true
				gunModule.Scoping(false)
			else
				reloadingLabel.Visible = false
			end
		end)

		gunModule.gunConfig.currentBullet.Changed:Connect(function()
			ammoLabel.Text = gunModule.gunConfig.currentBullet.Value.."/"..gunModule.gunConfig.maxBullet.Value
		end)
	end
end

function gunModule.unUI()
	if not gunModule.plrObject.Plr then return end
	if gunModule.plrObject.PlrGui:FindFirstChild(gunModule.gunConfig.GunUI.Name) then
		gunModule.plrObject.PlrGui:FindFirstChild(gunModule.gunConfig.GunUI.Name):Destroy()
	end

	gunModule.MobileUI.crossHairMobile.Visible = false
	gunModule.MobileUI.reloadMobile.Visible = false
	gunModule.MobileUI.FireMobile.Visible = false
	gunModule.MobileUI.rollMobile.Visible = false
	if mm then
		mm:Disconnect()
	end
end


function gunModule.rollMovement(moveControl)
	if not gunModule.plrObject.Plr then return end
	if gunModule.rollingConfig.isRolling == false and gunModule.rollingConfig.canRoll == true then
		gunModule.rollingConfig.isRolling = true
		gunModule.rollingConfig.rollAnim:Play()
		local linearVelocity = Instance.new("LinearVelocity")
		linearVelocity.MaxForce = math.huge
		linearVelocity.VelocityConstraintMode = Enum.VelocityConstraintMode.Vector
		local initializingVelocity
		if moveControl == "Front" then
			initializingVelocity = gunModule.plrObject.hrp.CFrame.LookVector * gunModule.rollingConfig.rollSpeed
		elseif moveControl == "Back" then
			initializingVelocity = -(gunModule.plrObject.hrp.CFrame.LookVector) * gunModule.rollingConfig.rollSpeed
		elseif moveControl == "Right" then
			initializingVelocity = gunModule.plrObject.hrp.CFrame.RightVector * gunModule.rollingConfig.rollSpeed
		elseif moveControl == "Left" then
			initializingVelocity = -(gunModule.plrObject.hrp.CFrame.RightVector) * gunModule.rollingConfig.rollSpeed
		end
		if not initializingVelocity then
			linearVelocity.VectorVelocity = gunModule.plrObject.hrp.CFrame.LookVector * gunModule.rollingConfig.rollSpeed
		else
			linearVelocity.VectorVelocity = initializingVelocity
		end
		linearVelocity.Attachment0 = Instance.new("Attachment", gunModule.plrObject.hrp)
		linearVelocity.Parent = gunModule.plrObject.hrp
		task.wait(gunModule.rollingConfig.rollDuration)
		linearVelocity:Destroy()
		task.wait(gunModule.rollingConfig.rollCooldown)
		gunModule.rollingConfig.isRolling = false
	end
end

function gunModule.checkRayRoll()
	if not gunModule.plrObject.Plr then return end
	if not gunModule.plrObject.hrp or not gunModule.plrObject.camera then return false end
	if not gunModule.plrObject.char:FindFirstChildOfClass("Tool") then return false end
	local rayStart = gunModule.plrObject.hrp.Position
	local rayDirection = gunModule.plrObject.hrp.CFrame.LookVector * 5
	local raycastParams = RaycastParams.new()
	raycastParams.FilterDescendantsInstances = {gunModule.plrObject.char}
	raycastParams.FilterType = Enum.RaycastFilterType.Exclude

	local raycastResult = workspace:Raycast(rayStart, rayDirection, raycastParams)

	if raycastResult then
		local distanceToHit = (raycastResult.Position - gunModule.plrObject.hrp.Position).Magnitude
		local rollThreshold = 4
		if distanceToHit <= rollThreshold then
			return false
		end
	end
	return true
end

function gunModule.continouscheckRoll()
	gunModule.rollingConfig.canRoll = gunModule.checkRayRoll()
end



function gunModule.inputBegan(input, isTyping)
	if isTyping or not gunModule.state.ExpectingInput then return end
	if input.UserInputType == Enum.UserInputType.MouseButton1 and gunModule.state.playerMouse ~= nil then
		gunModule.state.isMouse1down = true
		task.wait(gunModule.gunConfig.gunCooldown.Value)
		gunModule.state.isMouse1down = false
	elseif input.UserInputType == Enum.UserInputType.MouseButton2 and gunModule.state.playerMouse ~= nil then
		gunModule.state.isMouse2down = true		
		gunModule.Scoping(true)
	elseif input.KeyCode == Enum.KeyCode.Space and gunModule.state.playerMouse ~= nil then
		if gunModule.scopeState.IsScoping == true then
			if uis:IsKeyDown(Enum.KeyCode.A) then
				rollMovementControl = "Left"
			elseif uis:IsKeyDown(Enum.KeyCode.D) then
				rollMovementControl = "Right"
			elseif uis:IsKeyDown(Enum.KeyCode.S) then
				rollMovementControl = "Back"  
			elseif uis:IsKeyDown(Enum.KeyCode.W) then
				rollMovementControl = "Front"  
			end
			gunModule.rollMovement(rollMovementControl)
		end
	elseif input.KeyCode == Enum.KeyCode.LeftShift and gunModule.state.playerMouse ~= nil then
		gunModule.gunEvents.sprintEvent:FireServer(true)
	elseif input.KeyCode == Enum.KeyCode.R and gunModule.state.playerMouse ~= nil then
		if gunModule.gunConfig.isReloading.Value == false then
			gunModule.gunEvents.firingEvent:FireServer(nil,true)
		end
	end
end

function gunModule.inputEnded(input, isTyping)
	if isTyping or not gunModule.state.ExpectingInput then return end
	if input.UserInputType == Enum.UserInputType.MouseButton2 and gunModule.state.playerMouse ~= nil then
		gunModule.state.isMouse2down = false
		gunModule.Scoping(false)
	elseif input.KeyCode == Enum.KeyCode.LeftShift and gunModule.state.playerMouse ~= nil then
		gunModule.gunEvents.sprintEvent:FireServer(false)
	end
end


function gunModule.onEquip(mouse)
	gunModule.state.playerMouse = mouse
	gunModule.state.ExpectingInput = true
	gunModule.state.isMouse1down = false
	gunModule.state.isMouse2down = false
	gunModule.UIHandler()
end

function gunModule.unEquipped()
	gunModule.state.playerMouse = nil
	gunModule.state.ExpectingInput = false
	gunModule.state.isMouse1down = false
	gunModule.state.isMouse2down = false
	gunModule.unUI()
end



runService.RenderStepped:Connect(function()
	if gunModule.scopeState.IsScoping then
		print("The scoping is enabled")
	else
		warn("Scoping is disabled")
	end
	
end)




return gunModule

And here is the local script where I call the activation

local gun = script.Parent
local uis = game:GetService('UserInputService')
local runService = game:GetService("RunService")
local RS = game:GetService("ReplicatedStorage")
local Modules = RS:WaitForChild("1v1"):WaitForChild("Modules")
local gunModule = require(Modules:WaitForChild("gunModule"))
local configMovement = gun:WaitForChild("ConfigMovement")
local configSystem = gun:WaitForChild("Config")

local maxBullet = configSystem.MaxBullet
local currentBullet = configSystem.currentBullet
local isReloading = configSystem.isReloading
local cooldown = configSystem.Cooldown
local Sounds = gun:WaitForChild("Sounds")
local reload = Sounds:WaitForChild("Reload")

local UIFolder = gun:WaitForChild("UI")
local EventsFolder = gun:WaitForChild("Events")
local animationFolder = gun:WaitForChild("Animation")

local gunUI = UIFolder:WaitForChild("GunUI")
local hitMarkUI = UIFolder:WaitForChild("HitMarkUI")

local sprintEvent = EventsFolder:WaitForChild("Sprint")
local fireEvent = EventsFolder:WaitForChild("Sprint")

local scopeIdleAnim = animationFolder:WaitForChild("ScopedIDLE")
local rollAnim = animationFolder:WaitForChild("Roll")

local cooldown = configSystem.Cooldown

local function loadData()
	gunModule.plrObject.Plr = game:GetService("Players").LocalPlayer
	gunModule.plrObject.char = gunModule.plrObject.Plr.Character or gunModule.plrObject.Plr.CharacterAdded:Wait()
	gunModule.plrObject.hrp = gunModule.plrObject.char:WaitForChild("HumanoidRootPart")
	gunModule.plrObject.hum = gunModule.plrObject.char:WaitForChild("Humanoid")
	gunModule.plrObject.camera = workspace.CurrentCamera
	gunModule.plrObject.PlrGui = gunModule.plrObject.Plr:WaitForChild("PlayerGui")
	gunModule.MobileUI.mobileAssistant = gunModule.plrObject.PlrGui:WaitForChild("MobileAssistant")
	gunModule.MobileUI.crossHairMobile = gunModule.MobileUI.mobileAssistant:WaitForChild("CrossHair")
	gunModule.MobileUI.reloadMobile = gunModule.MobileUI.mobileAssistant:WaitForChild("Reload")
	gunModule.MobileUI.FireMobile = gunModule.MobileUI.mobileAssistant:WaitForChild("Firing")
	gunModule.MobileUI.rollMobile = gunModule.MobileUI.mobileAssistant:WaitForChild("Roll")
	gunModule.MobileUI.sprintMobile = gunModule.MobileUI.mobileAssistant:WaitForChild("Sprint")
	gunModule.rollingConfig.isRolling = false
	gunModule.rollingConfig.rollSpeed = configMovement.rollSpeed.Value
	gunModule.rollingConfig.rollDuration = 0.3
	gunModule.rollingConfig.rollAnim = gunModule.plrObject.hum:LoadAnimation(rollAnim)
	gunModule.rollingConfig.rollCooldown = 2
	gunModule.gunConfig.GunUI = gunUI
	gunModule.gunConfig.isReloading = isReloading
	gunModule.gunConfig.firingEvent = fireEvent
	gunModule.gunConfig.maxBullet = maxBullet
	gunModule.gunConfig.currentBullet = currentBullet
	gunModule.gunConfig.gunCooldown = cooldown
	gunModule.gunEvents.sprintEvent = sprintEvent
	gunModule.gunEvents.firingEvent = fireEvent
	gunModule.scopeState.scopeIdleAnim = gunModule.plrObject.hum:LoadAnimation(scopeIdleAnim)
end

loadData()

uis.InputBegan:Connect(gunModule.inputBegan)
uis.InputEnded:Connect(gunModule.inputEnded)
gun.Equipped:Connect(gunModule.onEquip)
gun.Unequipped:Connect(gunModule.unEquipped)

I tried so many other ways to fix it, i just ran out of options and needed assistance. If anyone has ever experienced an issue like this, please tell me how you fixed it. Thank you so much

Any help is very appreciated.

And also I forgot to mention, whenever I join, there is an untraceable error I can’t define what it is, perhaps anyone knows?

2 Likes

Try removing the isTyping part from this check in both your event connections. For clarification, this boolean is not a value for if the player is typing, it is if the game processed the event before it fired the inputBegan and inputEnded event. Right clicking the mouse to move your camera is probably firing this event with this value being true. Since you actually want scoping to end or start even when the player is moving the mouse, you should allow this call through.

Also, if you are still having issues with this, I recommend using ContextActionService instead. You can set priorities here when you use :BindActionAtPriority(), allowing you to overwrite any other inputs that share your right click for your scope function.

3 Likes

I have tried removing the isTyping part, however it didn’t work, can you tell me on how should I use :BindActionAtPriority()?

1 Like

Instead of connecting to InputBegan, you would bind a specific action like MouseButton2. The roblox API page on this already has a great example of how to use this. I think just :BindAction() may work, and it already has a great example there.

3 Likes

Thank you! I’ll try this as soon as I can :slight_smile:

1 Like

It didn’t work, it did activate it but through this I found the problem, the renderstep doesn’t activate anymore after the player makes movement or presses any certain key. The Camera offset also resets back to Vector3 (0,0,0).

I tried setting the priority value of the renderstep but it didn’t work, I also tried the renderstep directly instead of binding it. The render step did run and didn’t stop however, the camera offset still resets back to 0,0,0. I also forcefully keep the value at 3,0,0 but the resetting is way too obvious and it hinders the movement significantly.

What could be causing this?

I can’t be exactly sure about what is going on here. Can you try printing in the functions that you BindToRenderstepped to see if and when it is being called? Also, maybe resend the code, so that I can see the changes may help. Honestly, its hard to tell what is going on when I can’t see what you are pressing so maybe print that out too if you test it again.

I am also confused with this video still by the way. I think it is also possible I am misunderstanding what is going on here. Is it just you walking that disables the scope? In the bottom of your output it says scoping is enabled when you walk, but the scope is not zoomed in anymore. If this is the issue, are you sure IsScoping is actually giving the true value of the gun being scoped?

If I am correct in my interpretation of what the issue is here, maybe calling gunModule.Scoping is the problem. You do this three times throughout the script: one for inputBegan and inputEnded, but also one for reloading. In the reloading phase you did not set IsScoping to anything. Are you calling Scoping from here by accident or something? It would explain why the gun seems unscoped but the output still prints IsScoping as true.

Yes, you’re correct in your interpretation, although the scoping function still says it’s enabled, the scoping zoomed doesn’t work anymore. This is the issue, it resets whenever a players presses a key or moves.

Also about the reloading, isScoping value changes when you call the function, so it doesn’t have to necessarily be changed in that, I could just simply call the function to false and then the IsScoping will set to false. I also tried not calling any disable function. But none of it worked :frowning:

So the movement seems to somehow overwrite camera settings. I’ve never dealt with this, so I don’t know how to fix this exact problem, but maybe try creating your own shiftlock function since it will help the camera stay in the locked position you want it to be in when scoped. Set it to true when you scope and false when you unscope. Here is a great tutorial explaining how to do that. The main code for the function looks like this (I removed the camera offset part because you might not want that):

--Toggle Function:
function shiftLock(active) --Toggle shift.lock function
	if active then		
		hum.AutoRotate = false --Disable the automatic rotation since we are the ones setting it.

		RunService:BindToRenderStep("ShiftLock", Enum.RenderPriority.Character.Value, function()
			UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter --Set the mouse to center every frame.

			local _, y = workspace.CurrentCamera.CFrame.Rotation:ToEulerAnglesYXZ() --Get the angles of the camera
			root.CFrame = CFrame.new(root.Position) * CFrame.Angles(0,y,0) --Set the root part to the camera's rotation
		end) 
	else
		hum.AutoRotate = true --Let the humanoid handle the camera rotations again.
		RunService:UnbindFromRenderStep("ShiftLock") -- Allow mouse to move freely.
		UserInputService.MouseBehavior = Enum.MouseBehavior.Default -- Let the mouse move freely
	end
end

Thank you very much for helping me, I have found the problem.

This was the issue

Module Script

local function loadData()
	gunModule.state.playerMouse = nil
	gunModule.state.ExpectingInput = false
	gunModule.state.isMouse1down = false
	gunModule.state.isMouse2down = false
	gunModule.state.Disable = false
	
	gunModule.plrObject.Plr = nil
	gunModule.plrObject.PlrGui = nil
	gunModule.plrObject.char = nil
	gunModule.plrObject.hum = nil
	gunModule.plrObject.hrp = nil
	gunModule.plrObject.camera = nil


	gunModule.rollingConfig.isRolling = false
	gunModule.rollingConfig.canRoll = false
	gunModule.rollingConfig.rollSpeed = false
	gunModule.rollingConfig.rollDuration = false
	gunModule.rollingConfig.rollAnim = nil
	gunModule.rollingConfig.rollCooldown = 2


	gunModule.MobileUI.mobileAssistant = nil
	gunModule.MobileUI.crossHairMobile = nil
	gunModule.MobileUI.reloadMobile = nil
	gunModule.MobileUI.FireMobile = nil
	gunModule.MobileUI.rollMobile = nil
	gunModule.MobileUI.sprintMobile = nil


	gunModule.gunConfig.GunUI = nil
	gunModule.gunConfig.isReloading = nil
	gunModule.gunConfig.maxBullet = nil
	gunModule.gunConfig.currentBullet = nil
	gunModule.gunConfig.isFiring = false
	gunModule.gunConfig.gunCooldown = nil


	gunModule.gunEvents.sprintEvent = nil
	gunModule.gunEvents.firingEvent = nil


	gunModule.scopeState.scopeIdleAnim = nil
	gunModule.scopeState.IsScoping = false
end

loadData()

Local Script

local function loadData()
	gunModule.plrObject.Plr = game:GetService("Players").LocalPlayer
	gunModule.plrObject.char = gunModule.plrObject.Plr.Character or gunModule.plrObject.Plr.CharacterAdded:Wait()
	gunModule.plrObject.hrp = gunModule.plrObject.char:WaitForChild("HumanoidRootPart")
	gunModule.plrObject.hum = gunModule.plrObject.char:WaitForChild("Humanoid")
	gunModule.plrObject.camera = workspace.CurrentCamera
	gunModule.plrObject.PlrGui = gunModule.plrObject.Plr:WaitForChild("PlayerGui")
	gunModule.MobileUI.mobileAssistant = gunModule.plrObject.PlrGui:WaitForChild("MobileAssistant")
	gunModule.MobileUI.crossHairMobile = gunModule.MobileUI.mobileAssistant:WaitForChild("CrossHair")
	gunModule.MobileUI.reloadMobile = gunModule.MobileUI.mobileAssistant:WaitForChild("Reload")
	gunModule.MobileUI.FireMobile = gunModule.MobileUI.mobileAssistant:WaitForChild("Firing")
	gunModule.MobileUI.rollMobile = gunModule.MobileUI.mobileAssistant:WaitForChild("Roll")
	gunModule.MobileUI.sprintMobile = gunModule.MobileUI.mobileAssistant:WaitForChild("Sprint")
	gunModule.rollingConfig.isRolling = false
	gunModule.rollingConfig.rollSpeed = configMovement.rollSpeed.Value
	gunModule.rollingConfig.rollDuration = 0.3
	gunModule.rollingConfig.rollAnim = gunModule.plrObject.hum:LoadAnimation(rollAnim)
	gunModule.rollingConfig.rollCooldown = 2
	gunModule.gunConfig.GunUI = gunUI
	gunModule.gunConfig.isReloading = isReloading
	gunModule.gunConfig.firingEvent = fireEvent
	gunModule.gunConfig.maxBullet = maxBullet
	gunModule.gunConfig.currentBullet = currentBullet
	gunModule.gunConfig.gunCooldown = cooldown
	gunModule.gunEvents.sprintEvent = sprintEvent
	gunModule.gunEvents.firingEvent = fireEvent
	gunModule.scopeState.scopeIdleAnim = gunModule.plrObject.hum:LoadAnimation(scopeIdleAnim)
end

loadData()

These 2 function is what caused my script to not function normally. I have to find a way to slowly load them overtime. Do you have any fixes for that?

It warns me every time I join in

What do you mean by slowly loading them overtime? I can’t tell exactly what would be causing the issue here. As long as you set the values before you use them, it should work fine.

This might not be your scripts, it could be a plugin or roblox.

oh? can you give more explanation about this? how can it not be my script

Roblox and plugins that run in studio also can send their own messages to console to warn about something (usually it is just a bug on their end). If you don’t notice anything strange or anything that is inhibiting you it is probably fine. I am curious, however, can you click this output? Like will it take you to a script. Also does it say where it comes from. If you can’t do both of these things it probably isn’t your script.

That is perhaps correct, I tried to slowly load them by placing them into a table, and iterate through them with for loop but that problem still shows

this is my script my new load function

local function loadData()
	local tableToLoad
	local function loadPlayer()
		gunModule.plrObject.Plr = game:GetService("Players").LocalPlayer
		gunModule.plrObject.char = gunModule.plrObject.Plr.Character or gunModule.plrObject.Plr.CharacterAdded:Wait()
		gunModule.plrObject.hrp = gunModule.plrObject.char:WaitForChild("HumanoidRootPart")
		gunModule.plrObject.hum = gunModule.plrObject.char:WaitForChild("Humanoid")
		gunModule.plrObject.camera = workspace.CurrentCamera
		gunModule.plrObject.PlrGui = gunModule.plrObject.Plr:WaitForChild("PlayerGui")
	end

	local function loadUI()
		gunModule.MobileUI.mobileAssistant = gunModule.plrObject.PlrGui:WaitForChild("MobileAssistant")
		gunModule.MobileUI.crossHairMobile = gunModule.MobileUI.mobileAssistant:WaitForChild("CrossHair")
		gunModule.MobileUI.reloadMobile = gunModule.MobileUI.mobileAssistant:WaitForChild("Reload")
		gunModule.MobileUI.FireMobile = gunModule.MobileUI.mobileAssistant:WaitForChild("Firing")
		gunModule.MobileUI.rollMobile = gunModule.MobileUI.mobileAssistant:WaitForChild("Roll")
		gunModule.MobileUI.sprintMobile = gunModule.MobileUI.mobileAssistant:WaitForChild("Sprint")
	end

	local function loadConfig()
		gunModule.rollingConfig.isRolling = false
		gunModule.rollingConfig.rollSpeed = configMovement.rollSpeed.Value
		gunModule.rollingConfig.rollDuration = 0.3
		gunModule.rollingConfig.rollAnim = gunModule.plrObject.hum:LoadAnimation(rollAnim)
		gunModule.rollingConfig.rollCooldown = 2

	end
	local function restLoader()
		gunModule.gunConfig.GunUI = gunUI
		gunModule.gunConfig.isReloading = isReloading
		gunModule.gunConfig.firingEvent = fireEvent
		gunModule.gunConfig.maxBullet = maxBullet
		gunModule.gunConfig.currentBullet = currentBullet
		gunModule.gunConfig.gunCooldown = cooldown
		gunModule.gunEvents.sprintEvent = sprintEvent
		gunModule.gunEvents.firingEvent = fireEvent
		gunModule.scopeState.scopeIdleAnim = gunModule.plrObject.hum:LoadAnimation(scopeIdleAnim)
	end

	tableToLoad = {
		loadPlayer(),
		loadUI(),
		loadConfig(),
		restLoader(),
	}
	return tableToLoad
end


local tableToLoad = loadData()
for _, data in pairs(tableToLoad) do
	task.wait(.3)
	data()
end

I did the same for the client

I created a new roblox place, and used my scripts there, the error still shows but the the module and local scripts i made worked perfectly fine there. I rechecked my previous game scripts many times but still have not found any script that could tamper with the camera. I may start digging through them again. Thank you very much for helping me :slight_smile:

I still don’t understand. Why slowly load everything. Whenever I load something, I would do it all at once so there is no waiting for the scripts to function.

Also, you called these functions in the table meaning you are executing them twice. If you really think this is needed, store the functions without execution like this:

tableToLoad = {
		loadPlayer,
		loadUI,
		loadConfig,
		restLoader,
	}

That is very strange, but I am glad it is fixed now!