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.
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)
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)
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.