How can I make the Tools Lock on my Screen?

I am currently trying to make the tools that the player equips show up on the screen better. How would/can I achieve this feature? (an example of this is in Roblox Bedwars, where the tool doesn’t move off of your screen when you move your camera)

The issue is that the default tool holding in the first person doesn’t lock the tool on the screen, if you look down the tool will be almost entirely off of the screen.

I tried messing around with Viewport Frames but it didn’t work, and I just gave up after like an hour.

2 Likes

i dont kno who wto exactly but you can look into like fps frame work where the gun doesnt leave the screen its basically the same thing.

2 Likes

I feel more comfortable being able to make the code myself, not taking code from free models that potentially have viruses.

1 Like

i ment like tutorials on youtube videos or here on devforum

1 Like

maybe you can attach the tool to the camera somehow?

1 Like

Still looking for a solution btw, I really need this for my game.

There are two ways you can do it.

One is to put it inside a ViewportFrame. This solution prevents tool clipping. Unfortunately, with that you will have limited visuals.

The other way to do it is to bind a function to each render step which positions the Tool at that point Infront of the Player. It will require you to create a way to separate what other players see vs what you see or else others will see your Tool move too

Alternatively you could in theory modify the ToolGrip position or the Motor6D which controls the Rig where the tool attaches to the Characters arm. (A lot harder to do)

1 Like

I think I will try the first one, but how will I make the tool invisible on the client so the real tool wont be in back of the viewport frame?

You can simply detect when the player zooms in (or you can just detect when the body parts on client go transparent) and then change the transparency of the tool the match that.

Hey there. I don’t usually make entire scripts but I thought it is an interesting things to tackle. So, I just wanted to share this piece of code. I also added a way to get the lighting direction too.

it doesn’t seem to work when the player resets or when you re equip a tool. (it’s just a demo)

https://gyazo.com/5eeae0291ac2114db7b9da9ce712e54d

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

local Character = Player.Character
local Humanoid: Humanoid = Character:WaitForChild("Humanoid")
local Camera: Camera = workspace.CurrentCamera
local PlayerGui = Player.PlayerGui

local EquippedTool: Tool = nil
local Handle: BasePart = nil
local ToolOffset: CFrame = CFrame.new()

local SunDirection = Lighting:GetSunDirection()

local ViewportFrame = PlayerGui.ScreenGui.ViewportFrame
--ViewportFrame.CurrentCamera = Camera

local Connection: RBXScriptConnection = nil

Character.DescendantAdded:Connect(function(descendant: Instance)
	if descendant:IsA("Tool") then
		local Tool: Tool = descendant
		local Handle = Tool:WaitForChild("Handle")
		
		local ToolClone = Tool:Clone()
		ToolClone.Parent = ViewportFrame.WorldModel
		for _, Instance: Instance in ipairs(Tool:GetChildren()) do
			if Instance:IsA("BasePart") then
				Instance.Transparency = 1
			end
		end
		Connection = RunService.RenderStepped:Connect(function()
			ViewportFrame.LightDirection = Camera.CFrame:VectorToWorldSpace(SunDirection)
			ToolClone.Handle.CFrame = Character.Head.CFrame:ToObjectSpace(Tool.Handle.CFrame)
		end)
		Tool.Unequipped:Wait()
		ToolClone:Destroy()
		Connection:Disconnect()
	end
end)

Place in StarterCharacterScripts. Make sure you add ScreenGui>ViewportFrame>WorldModel. I haven’t tested with Welded tools yet.

1 Like