Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Executing a script produces an error please help?

When executing the script it produces the error Workspace.Combatives Armory.SD HR.Head.GUI:21: attempt to index a nil value

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 onTouch(part) 

local human = part.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.Touched:connect(onTouch) 

1 answer

✓ Accepted answer

First of all, make sure there is an object named "FlashGUI" and its parent is wherever you search it. If you are sure that is not the problem, split that line into different lines and see what is the real problem. I would suggest it like:

FGUI = script.Parent.Parent:FindFirstChild("FlashGUI")
if FGUI then
	FC = FGUI:Clone()
	FC.Parent = player.PlayerGui
else
	print("Such gui is not found")
end

This discussion is preserved as it was. New answers, comments, and votes are closed.