#Viewmodel script not really working as planned for my fps
1 messages · Page 1 of 1 (latest)
ill try to post the script i used
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local camera = workspace.CurrentCamera
local viewmodelPath = game.ReplicatedStorage:WaitForChild("Viewmodel")
local viewmodelModel = viewmodelPath:Clone()
viewmodelModel.Parent = camera
local requiredToolName = "TROY DEFENSE AR"
local viewmodelOffset = CFrame.new(0, 0, 0)
local function isHoldingTool(toolName: string): boolean
if player.Character then
local tool = player.Character:FindFirstChild(toolName)
return tool ~= nil and tool:IsA("Tool")
end
return false
end
local function updateCamera()
if isHoldingTool(requiredToolName) and viewmodelModel then
viewmodelModel:PivotTo(camera.CFrame * viewmodelOffset)
end
end
RunService.RenderStepped:Connect(updateCamera)
if player.Character then
player.Character.ChildAdded:Connect(function(child)
if child:IsA("Tool") and child.Name == requiredToolName then
for _, part in ipairs(player.Character:GetDescendants()) do
if part:IsA("BasePart") or part:IsA("Decal") then
part.Transparency = 1
end
end
end
end)
player.Character.ChildRemoved:Connect(function(child)
if child:IsA("Tool") and child.Name == requiredToolName then
for _, part in ipairs(player.Character:GetDescendants()) do
if part:IsA("BasePart") or part:IsA("Decal") then
part.Transparency = 0
end
end
end
end)
end
create the viewmodel when the tool is equipped
destroy it when the tool is unequipped
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local camera = workspace.CurrentCamera
local viewmodelPath = game.ReplicatedStorage:WaitForChild("Viewmodel")
local viewmodelModel = nil -- start empty
local requiredToolName = "TROY DEFENSE AR"
local viewmodelOffset = CFrame.new(0, 0, 0)
local function isHoldingTool(toolName: string): boolean
if player.Character then
local tool = player.Character:FindFirstChild(toolName)
return tool ~= nil and tool:IsA("Tool")
end
return false
end
local function updateCamera()
if isHoldingTool(requiredToolName) then
if not viewmodelModel then
viewmodelModel = viewmodelPath:Clone()
viewmodelModel.Parent = camera
end
viewmodelModel:PivotTo(camera.CFrame * viewmodelOffset)
else
if viewmodelModel then
viewmodelModel:Destroy()
viewmodelModel = nil
end
end
end
RunService.RenderStepped:Connect(updateCamera)
if player.Character then
player.Character.ChildAdded:Connect(function(child)
if child:IsA("Tool") and child.Name == requiredToolName then
for _, part in ipairs(player.Character:GetDescendants()) do
if part:IsA("BasePart") or part:IsA("Decal") then
part.Transparency = 1
end
end
end
end)
player.Character.ChildRemoved:Connect(function(child)
if child:IsA("Tool") and child.Name == requiredToolName then
for _, part in ipairs(player.Character:GetDescendants()) do
if part:IsA("BasePart") or part:IsA("Decal") then
part.Transparency = 0
end
end
end
end)
end
This should fix it
that did make the Viewmodel goes away but how do i make the item stay in my inventory, i need it to stay and not just get deleted
And how do I do it
Alright
or is the tool in ReplicatedStorage?
The tool is in the starterpack, that way I can have it at start of game
** You are now Level 1! **
now is done
Huh?
this: that did make the Viewmodel goes away but how do i make the item stay in my inventory, i need it to stay and not just get deleted
need any help?
...