Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to put tool on the player's head?

Asked by 3 years ago

Hello! I would like to know what is wrong in my code, I want the night vision tool to appear in the player's head, how can I do that?


local tool = script.Parent local equipped = false local UID = game:GetService("UserInputService") local player = game.Players.LocalPlayer local char = player.Character tool = char.Head.CFrame 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)

1 answer

Log in to vote
0
Answered by 3 years ago

Ok, to start you don't need to use user input service when you're using activated because that automatically detects when the tool is equipped and when it is left-clicked (however if you want other inputs with your tool you should still use User Input Service.) Also is this a server or local script, because you cant use things like ".LocalPlayer" on server scripts so that could be part of your problem.

Ad

Answer this question