Mobile Shiftlock

Hello. I am trying to make my guns mobile-friendly and I want the players to have shiftlock while aiming with the guns. I found this (ex: 1) service that does that for you, but I dont need this for PC, so how can I delete the module scripts via a local script?

Thanks

ex: 1
image

4 Likes

im pretty sure local scripts cannot access anything on the server so i dont think they will be able to detect the module scripts

if it is possible however, all youll have to do is put in the module scripts’ destination and follow it with the :Destroy() method

1 Like

there are also ways to detect if a client is on a certain device so you could disregard this entirely and write a function that detects which device the client is on, but i am not the person to ask and im 100% certain that there are other posts on this topic if you need help

1 Like

Should I do that for all of the module scripts? And if so, how might I do that?

2 Likes

you should only have to do it for the scripts that are required for the shiftlock. since they are module scripts, you could also find the script that is requiring the module scripts and first have it check if the client is on the right device then have it require the scripts, which either one works best for you

1 Like

remove module scripts via a local script in Roblox, you can iterate through the descendants of the player’s character or a specific location in the game and remove the module scripts that you do not need. Here is an example of how you can achieve this:

local Players = game:GetService("Players")

local function removeModuleScripts()
    local player = Players.LocalPlayer
    local character = player.Character or player.CharacterAdded:Wait()

    for _, descendant in ipairs(character:GetDescendants()) do
        if descendant:IsA("ModuleScript") then
            descendant:Destroy()
        end
    end
end

-- Call the function to remove module scripts
removeModuleScripts()

This script gets the player’s character and iterates through all its descendants. If it finds a module script, it destroys it.

If you want to target a specific location instead of the character, you can change the character variable to point to that location. For example, if your module scripts are all under a specific folder in the game, you can adjust the script like this:

local specificFolder = game.Workspace.YourFolderName -- Change this to the path of your folder

local function removeModuleScriptsFromFolder(folder)
    for _, descendant in ipairs(folder:GetDescendants()) do
        if descendant:IsA("ModuleScript") then
            descendant:Destroy()
        end
    end
end

-- Call the function to remove module scripts from the specific folder
removeModuleScriptsFromFolder(specificFolder)

Make sure to replace YourFolderName with the actual name of the folder you are targeting.

2 Likes

this would run as soon as the client loads right? the op is looking for this to fire if the client is on mobile so for this to be effective for their requests you would first have to determine if the client is on the right device right? ive only been scripting in luau for a couple months now so im just asking for clarification

1 Like

Yes, you are correct. To ensure that the script only runs on a mobile client, you need to check the device type before executing the removal of module scripts. Roblox provides a way to determine the client’s device type using the UserInputService.

2 Likes

thanks for the feedback! (filler)

1 Like

When I load into the game and destroy the module scripts, they appear to keep running in the background… I am really confused rn…

1 Like

I can see this because even when the script is gone it is spamming errors:

image

2 Likes

can you send a ss of the console? to determine if its only running on mobile, youll have to go to the “test” tab at the top of studio and click the “device” option, there you can select the dropdown and pick from a variety of mobile devices

1 Like

2 Likes

first of all, it would be easier to enable the output directly in studio rather than opening the console within the test

it looks like error is running within your module scripts from before, im assuming since youre trying to mess with shiftlock that you copied and pasted the build in camera scripts, are you sure youve put these scripts in the right destination theyre supposed to be in?

im not too great with things like this but sending a ss of the code around line 469 in the CameraModule script could help

Will be back in ~30 mins

1 Like

double check that the “PlayerModule” module script is parented under “StarterPlayer.StarterPlayerScripts”, as the script is looking for a boolean within the player instance, and is accessing it by calling the parent of the “PlayerModule” module script, so if its placed it the wrong spot, the script wont be able to find the player instance and will throw an error

module scripts have to be run with require() in another script in order to run

you can just check for mobile with userinputservice in that script and not run it

1 Like

thats what im trying to achieve here but theres a problem with the scripts themselves first

Those are roblox scripts, the Player Controller and the Camera basically. I don’t know what he is trying to do, but messing with the PlayerModule like that is bound to cause issues. It is possible to fork the PlayerModule (which would probably be a better solution), though not recommended as you wont get the changes roblox make to it

im pretty sure they did fork them, i think they didnt parent them correctly though

theyre trying to make a mobile shiftlock basically