So I tried to make a player invisible by clicking or tapping with the item and uhh this happens
Console:
15:35:01.700 Players.KamuWasTaken.Backpack.Invis Watch.CloakHandler:33: attempt to index nil with 'MainFrame' - Server - CloakHandler:33
here are the scripts:
CloakHandler:
local FADE_IN_TIME = 1
local DURATION = 15
local FADE_OUT_TIME = 1
local COOLDOWN = 10
local tool = script.Parent
local canActivate = tool.CanActivate
local function callOnChildren(object, func)
func(object)
for _, child in pairs(object:GetChildren()) do
if not child:IsA("Tool") or child == tool then
callOnChildren(child, func)
end
end
end
local function makeInvisible(object, delta, originalTransparencies)
if object:IsA("BasePart") or object:IsA("Decal") then
if not originalTransparencies[object] then
originalTransparencies[object] = object.Transparency
end
object.Transparency = originalTransparencies[object] + delta
end
end
local function onActivated()
local originalTransparencies = {}
originalTransparencies[tool.Handle] = 0
local character = tool.Parent
local plr = game.Players:GetPlayerFromCharacter(character)
local cloakGui = plr.PlayerGui:FindFirstChild("CloakGui")
local bar = cloakGui.MainFrame.BarBG.Bar
local fadeInSteps = FADE_IN_TIME * 30
if canActivate.Value then
canActivate.Value = false
script.Parent.Handle.WooshStart:Play()
if fadeInSteps <= 1 then
fadeInSteps = 1
end
for t = 0, fadeInSteps do
callOnChildren(character, function(object)
makeInvisible(object, t / fadeInSteps, originalTransparencies)
makeInvisible(tool, t / fadeInSteps, originalTransparencies)
end)
wait(1/30)
end
tool.Handle.Transparency = 1
else
script.Parent.Handle.WooshEnd:Play()
local fadeOutSteps = FADE_OUT_TIME * 30
for t = fadeOutSteps, 0, -1 do
callOnChildren(character, function(object)
makeInvisible(object, t / fadeOutSteps, originalTransparencies)
makeInvisible(tool, t / fadeInSteps, originalTransparencies)
end)
wait(1/30)
end
tool.Handle.Transparency = 0
canActivate.Value = true
-- tool.Handle.Transparency = 0
--local fadeInSteps = FADE_IN_TIME * 30
--if fadeInSteps <= 1 then
-- fadeInSteps = 1
--end
--for t = 0, fadeInSteps do
-- callOnChildren(character, function(object)
-- makeInvisible(object, t / fadeInSteps, originalTransparencies)
-- makeInvisible(tool, t / fadeInSteps, originalTransparencies)
-- end)
-- wait(1/30)
--end
--tool.Handle.Transparency = 1
--if bar.Size == UDim2.new(0, 0, 1, 0) then
-- script.Parent.Handle.WooshEnd:Play()
-- local fadeOutSteps = FADE_OUT_TIME * 30
-- for t = fadeOutSteps, 0, -1 do
-- callOnChildren(character, function(object)
-- makeInvisible(object, t / fadeOutSteps, originalTransparencies)
-- makeInvisible(tool, t / fadeInSteps, originalTransparencies)
-- end)
-- wait(1/30)
-- end
-- tool.Handle.Transparency = 0
--elseif bar.Size == UDim2.new(0, 0, 1, 0) then
-- local originalTransparencies = {}
-- originalTransparencies[tool.Handle] = 0
-- local character = tool.Parent
-- local fadeInSteps = FADE_IN_TIME * 30
-- script.Parent.Handle.WooshEnd:Play()
-- local fadeOutSteps = FADE_OUT_TIME * 30
-- for t = fadeOutSteps, 0, -1 do
-- callOnChildren(character, function(object)
-- makeInvisible(object, t / fadeOutSteps, originalTransparencies)
-- makeInvisible(tool, t / fadeInSteps, originalTransparencies)
-- end)
-- wait(1/30)
-- end
-- tool.Handle.Transparency = 0
--end
end
if bar.Size == UDim2.new(0, 0, 1, 0) then
script.Parent.Handle.WooshEnd:Play()
local fadeOutSteps = FADE_OUT_TIME * 30
for t = fadeOutSteps, 0, -1 do
callOnChildren(character, function(object)
makeInvisible(object, t / fadeOutSteps, originalTransparencies)
makeInvisible(tool, t / fadeInSteps, originalTransparencies)
end)
wait(1/30)
end
tool.Handle.Transparency = 0
canActivate.Value = true
end
end
tool.Activated:Connect(onActivated)
tool.Equipped:Connect(function()
if canActivate.Value then
tool.Handle.Transparency = 0
end
end)
BackpackHandler(players cant use any item):
local canActivated = script.Parent.CanActivate
local players = game:GetService("Players")
local lPLayer = players.LocalPlayer
local char = lPLayer.Character or lPLayer.CharacterAdded:Wait()
local cloakGui = lPLayer.PlayerGui:FindFirstChild("CloakGui")
local bar = cloakGui:FindFirstChild("MainFrame"):FindFirstChild("BarBG"):FindFirstChild("Bar")
script.Parent.Activated:Connect(function()
if canActivated.Value then
canActivated.Value = false
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false)
if bar.Size == UDim2.new(0, 0, 1, 0) then
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false)
end
wait(10)
canActivated.Value = true
end
end)
char.Humanoid.Died:Connect(function()
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,true)
end)
CloakBarHandler:
local bar = script.Parent
local cloak = 750
local cloakRate = 0
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local isCloaking = false
local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed or cloak == 0 then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
isCloaking = true
end
end)
while wait() do
if cloak == 0 and isCloaking then
isCloaking = false
end
--and humanoid.MoveDirection.Magnitude > 0
if isCloaking then
cloak = cloak - 1
wait(cloakRate)
else
cloak = cloak + 1
wait(cloakRate)
end
cloak = math.clamp(cloak, 0, 100)
bar.Size = UDim2.new((1/100) * cloak, 0, 1 ,0)
end
if you guys found the problem please reply with the code(if not is okay), thank you!
also this is the layout: