I am trying to create a hat remover gui when you wear the hat. Note: the hat is a custom hat and the following script is not mine. I found a model that has one so I tried to copy it and put it in mine but the hat remover gui does not work/become visible. I have tried to edit it myself but failed as the Output keeps saying:
Workspace.Helmet.FlashGUI.Frame.RH.Script:4: attempt to index local 'HLoc' (a nil value)
Here is a link of what my model contains of:
https://gyazo.com/d82629e4965c9256d2db6461cf439d1c
GUI Script:
local debounce = false
function getPlayer(humanoid)
local players = game.Players:children()
for i = 1, #players do
if players[i].Character.Humanoid == humanoid then return players[i] end
end
return nil
end
function onClick(click)
local human = click.Parent:findFirstChild("Humanoid")
if (human ~= nil) and debounce == false then
debounce = true
local player = getPlayer(human)
if (player == nil) then return end
script.Parent.Parent:findFirstChild("FlashGUI"):clone().Parent = player.PlayerGui
wait(5)
debounce = false
end
end
script.Parent.ClickDetector.MouseClick:connect(onClick)
Flash Script:
local P = script.Parent.Parent.Parent.Parent.Parent.Name
local HLoc = Workspace:FindFirstChild(P)
wait(1)
local Helmet = HLoc:findFirstChild("Face")
if Helmet ~= nil then
function Click(mouse)
Helmet:remove()
script.Parent.Parent.Parent:remove()
end
end
script.Parent.MouseButton1Down:connect(Click)
Hat Remover Section:
function onClicked(plr)
character = plr.Character
local d = character:GetChildren()
for i=1, #d do
if (d[i].className == "Part" or "Union") then
d[i]:remove()
end
end
Full Hat Script:
function onClicked(plr)
character = plr.Character
local d = character:GetChildren()
for i=1, #d do
if (d[i].className == "Part" or "Union") then
d[i]:remove()
end
end
character = plr.Character
if character:findFirstChild("Humanoid") ~= nil and character:findFirstChild("Face") == nil then
local g = script.Parent.Face:clone()
g.Parent = character
local C = g:GetChildren()
for i=1, #C do
if C[i].className == "Part" then
local W = Instance.new("Weld")
W.Part0 = g.Middle
W.Part1 = C[i]
local CJ = CFrame.new(g.Middle.Position)
local C0 = g.Middle.CFrame:inverse()*CJ
local C1 = C[i].CFrame:inverse()*CJ
W.C0 = C0
W.C1 = C1
W.Parent = g.Middle
g.Middle.Transparency = 1
end
local Y = Instance.new("Weld")
Y.Part0 = character.Head
Y.Part1 = g.Middle
Y.C0 = CFrame.new(0, 0, 0)
Y.Parent = Y.Part0
end
local h = g:GetChildren()
for i = 1, # h do
h[i].Anchored = false
h[i].CanCollide = false
end
end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
Please help me, thank you!

2 comments
I added the "" to the FindFirstChild(P) but it keeps making my character disappear and not able to move or reset. And the Gui does not show up.
which lines do these occur