Function override by an input?

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!

Thank you very much for this information

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