PipeSader
(PipeSader)
February 2, 2021, 1:24pm
#1
why the night viewer does not appear on the head? How do I do that configuration?
I need to make the night vision object be on the player’s head
localscript
local tool = script.Parent
local equipped = false
local UID = game:GetService("UserInputService")
tool.Equipped:Connect(function()
equipped = true
end)
tool.Unequipped:Connect(function()
equipped = false
end)
local isActivated = false
UID.InputBegan:Connect(function(key,isTyping)
if equipped == true then
print("tool equipped")
if key.KeyCode == Enum.KeyCode.N then
isActivated = not isActivated
if (isActivated) then
pcall(function()
local StarterGui = game:GetService("StarterGui")
StarterGui:SetCore("TopbarEnabled", false)
end)
local frame = game:GetService("Players").LocalPlayer.PlayerGui
print("Activated.")
-- Config 1
wait(.1)
frame.Screen:FindFirstChild("NightConfig").BackgroundTransparency = 0.1
wait(.1)
frame.Screen:FindFirstChild("NightConfig").BackgroundTransparency = 0.15
-- Config 2
wait(.1)
frame.Screen:FindFirstChild("NightConfig").BackgroundTransparency = 0.25
wait(.1)
frame.Screen:FindFirstChild("NightConfig").BackgroundTransparency = 0.4
wait(.1)
frame.Screen:FindFirstChild("NightConfig").BackgroundTransparency = 0.6
else
pcall(function()
local StarterGui = game:GetService("StarterGui")
StarterGui:SetCore("TopbarEnabled", true)
end)
local frame = game:GetService("Players").LocalPlayer.PlayerGui
frame.Screen:FindFirstChild("NightConfig").BackgroundTransparency = 1
print("no activated.")
end
end
end
end)
Can you show a script if you have one?
PipeSader
(PipeSader)
February 2, 2021, 1:34pm
#3
Sure!
localscript
local tool = script.Parent
local equipped = false
local UID = game:GetService("UserInputService")
tool.Equipped:Connect(function()
equipped = true
end)
tool.Unequipped:Connect(function()
equipped = false
end)
local isActivated = false
UID.InputBegan:Connect(function(key,isTyping)
if equipped == true then
print("tool equipped")
if key.KeyCode == Enum.KeyCode.N then
isActivated = not isActivated
if (isActivated) then
pcall(function()
local StarterGui = game:GetService("StarterGui")
StarterGui:SetCore("TopbarEnabled", false)
end)
local frame = game:GetService("Players").LocalPlayer.PlayerGui
print("Activated.")
-- Config 1
wait(.1)
frame.Screen:FindFirstChild("NightConfig").BackgroundTransparency = 0.1
wait(.1)
frame.Screen:FindFirstChild("NightConfig").BackgroundTransparency = 0.15
-- Config 2
wait(.1)
frame.Screen:FindFirstChild("NightConfig").BackgroundTransparency = 0.25
wait(.1)
frame.Screen:FindFirstChild("NightConfig").BackgroundTransparency = 0.4
wait(.1)
frame.Screen:FindFirstChild("NightConfig").BackgroundTransparency = 0.6
else
pcall(function()
local StarterGui = game:GetService("StarterGui")
StarterGui:SetCore("TopbarEnabled", true)
end)
local frame = game:GetService("Players").LocalPlayer.PlayerGui
frame.Screen:FindFirstChild("NightConfig").BackgroundTransparency = 1
print("no activated.")
end
end
end
end)
Do you have any errors???
PipeSader
(PipeSader)
February 2, 2021, 1:37pm
#6
No error, the script works perfectly
Wait, so you are wanting the NVG’s to go on the players head?
1 Like
PipeSader
(PipeSader)
February 2, 2021, 1:38pm
#9
yes, i need to make the night vision object be on the player’s head
You should set the NVG’s CFrame to the same as the players head.
Do not anchor it and set cancollide to true.
No, you do it in a script like this:
NVG.CFrame = character.Head.CFrame
PipeSader
(PipeSader)
February 2, 2021, 1:42pm
#13
How can I create the local character?
tool = script.Parent.Handle
tool.CFrame = character.Head.CFrame
PipeSader
(PipeSader)
February 2, 2021, 1:45pm
#14
Something like this or am i wrong?
local tool = script.Parent
local equipped = false
local UID = game:GetService("UserInputService")
tool.Equipped:Connect(function()
equipped = true
end)
tool.Unequipped:Connect(function()
equipped = false
end)
local isActivated = false
UID.InputBegan:Connect(function(key,isTyping)
if equipped == true then
print("tool equipped")
if key.KeyCode == Enum.KeyCode.N then
isActivated = not isActivated
if (isActivated) then
pcall(function()
local StarterGui = game:GetService("StarterGui")
StarterGui:SetCore("TopbarEnabled", false)
local player = game.Players.LocalPlayer
local char = player.Character
local tool = script.Parent.Handle
tool.CFrame = char.Head.CFrame
end)
local frame = game:GetService("Players").LocalPlayer.PlayerGui
print("Activated.")
-- Config 1
wait(.1)
frame.Screen:FindFirstChild("NightConfig").BackgroundTransparency = 0.1
wait(.1)
frame.Screen:FindFirstChild("NightConfig").BackgroundTransparency = 0.15
-- Config 2
wait(.1)
frame.Screen:FindFirstChild("NightConfig").BackgroundTransparency = 0.25
wait(.1)
frame.Screen:FindFirstChild("NightConfig").BackgroundTransparency = 0.4
wait(.1)
frame.Screen:FindFirstChild("NightConfig").BackgroundTransparency = 0.6
else
pcall(function()
local StarterGui = game:GetService("StarterGui")
StarterGui:SetCore("TopbarEnabled", true)
end)
local frame = game:GetService("Players").LocalPlayer.PlayerGui
frame.Screen:FindFirstChild("NightConfig").BackgroundTransparency = 1
print("no activated.")
end
end
end
end)
Pixeluted
(Pixeluted)
February 2, 2021, 2:21pm
#15
You would likely to use WeldConstraint so for this you will need make an WeldConstraint in the NightVision and set the Part0 = NightVision, In script we will set CFrame and WeldConstraint.Part1
local NightVision = game.ReplicatedStorage.NightVision:Clone()
NightVision.Parent = Player.Character
Player.Character.NightVision.CFrame = Player.Character.Head.CFrame
Player.Character.NightVision.WeldConstraint.Part1 = Player.Character.Head
You need to weld it to the head
Its like putting a hat on, you would use the same script as if you were putting on a hat
You could also use the tool holder editor plug in to move the handle to put it on the head