Is it possible to rewrite this localscript for a noclip tool so it can be used for PC, mobile AND console?

So I made a localscript for a noclip tool for my game, and it fully works for PC only.

I want to rewrite my localscript so my noclip tool works on all devices. However, I do not know if that’s possible yet.

It’s not like the noclip tool is broken or works in a different way than expected, it’s like the tool doesn’t work at all on mobile and console, since it’s only scripted for PC.

I have tried to rewrite the code several times to no avail. Sometimes the new code breaks the old code for PC but works for the other devices. Simply, what I’ve tried so far didn’t help.

Below is the localscript for my noclip tool.

local tool = script.Parent
local player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

local noclip = false
local fly = false
local flySpeed = 50


local gui = player:WaitForChild("PlayerGui"):WaitForChild("NoclipGUI")
local label = gui:WaitForChild("NoclipLabel")

local function updateGUI()
	if noclip then
		label.Text = "Fly + Noclip ON | Speed: " .. flySpeed
		label.TextColor3 = Color3.new(0, 1, 0)
	else
		label.Text = "Fly + Noclip OFF"
		label.TextColor3 = Color3.new(1, 0, 0)
	end
end


local function forceNoclip()
	if player.Character then
		for _, part in ipairs(player.Character:GetDescendants()) do
			if part:IsA("BasePart") then
				part.CanCollide = false
			end
		end
	end
end


local function toggle()
	noclip = not noclip
	fly = noclip
	updateGUI()
	print("Fly + Noclip toggled:", noclip)
end


tool.Activated:Connect(toggle)


UIS.InputBegan:Connect(function(input, gpe)
	if gpe then return end

	
	if input.KeyCode == Enum.KeyCode.N then
		toggle()
	end

	
	if input.KeyCode == Enum.KeyCode.E and fly then
		flySpeed = flySpeed + 10
		updateGUI()
		print("Speed increased to", flySpeed)
	end

	
	if input.KeyCode == Enum.KeyCode.Q and fly then
		flySpeed = math.max(5, flySpeed - 10)
		updateGUI()
		print("Speed decreased to", flySpeed)
	end
end)


RunService.RenderStepped:Connect(function()
	if fly and player.Character then
		forceNoclip()

		local char = player.Character
		local hrp = char:FindFirstChild("HumanoidRootPart")
		local hum = char:FindFirstChildWhichIsA("Humanoid")

		if hum then hum.PlatformStand = true end
		if not hrp then return end

		local move = Vector3.zero

		if UIS:IsKeyDown(Enum.KeyCode.W) then
			move = move + workspace.CurrentCamera.CFrame.LookVector
		end
		if UIS:IsKeyDown(Enum.KeyCode.S) then
			move = move - workspace.CurrentCamera.CFrame.LookVector
		end
		if UIS:IsKeyDown(Enum.KeyCode.A) then
			move = move - workspace.CurrentCamera.CFrame.RightVector
		end
		if UIS:IsKeyDown(Enum.KeyCode.D) then
			move = move + workspace.CurrentCamera.CFrame.RightVector
		end
		if UIS:IsKeyDown(Enum.KeyCode.Space) then
			move = move + Vector3.new(0, 1, 0)
		end
		if UIS:IsKeyDown(Enum.KeyCode.LeftControl) then
			move = move - Vector3.new(0, 1, 0)
		end

		if move.Magnitude > 0 then
			hrp.Velocity = move.Unit * flySpeed
		else
			hrp.Velocity = Vector3.new(0, 0, 0)
		end
	else
		if player.Character then
			local hum = player.Character:FindFirstChildWhichIsA("Humanoid")
			if hum then hum.PlatformStand = false end
		end
	end
end)

player.CharacterAdded:Connect(function()
	wait(0.3)
	if noclip then
		updateGUI()
	end
end)

I do not wish for anyone to rewrite the code in the replies, but I would rather if someone would simply tell me if it’s possible to rewrite this.

you could do it but you’d need to make adjustments

for example your speed increase and decrease, you’d probably have to remove them. you could use buttons in a gui instead though as it would work for all platforms.

show the gui when the tool is equipped, hide it when its not. use a BindableEvent to handle the buttons being clicked as you can fire them directly back to the client instead of server then client.

then you’d just change the toggle from a keybind to whenever the tool is activated

I would like to keep the PC keybinds though. What I want is there to be a keybind for all devices so each device has a different keybind, so one works for that device exclusively. And also I dont mind when the gui is shown

add console keybinds then, and for mobile you can use ContextActionService and bind them to a function which you would increase or decrease the speed in.

Ok, I will try this in a bit once I have enough time!

It worked! Thanks for the tips!

1 Like

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