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

Clone script won't work. Why?

script.Parent.Touched:connect(function(part)
local s = script.Gui:clone()
s.Parent = game.Players:FindFirstChild(part.Parent.Name).PlayerGui
end)

3 comments

0

Any errors?

0

Nothing. No errors. I'll check if there is any output.

0

it says, "Disconnected event because of exception".

3 answers

✓ Accepted answer

Make sure the humanoid is nil.

I'm guessing what's happening is that something else is hitting the part than a person. If a random flying object hits it, It'll fire, and attempt to find a player called "Part" or whatever the thing that hit it is called. Try putting this inside the function instead.

if part.Parent:FindFirstChild("Humanoid") ~= nil then
	local s = script.Gui:clone()
	s.Parent = game.Players:FindFirstChild(part.Parent.Name).PlayerGui
end

That'll ensure that whatever hit the part is a person and not some random brick.

Of course, if the part being hit is in an enclosed environment where nothing else can hit it, then I'm completely wrong.

1 comment

0

Oh... DERP. Thanks... Should of thought of that...

Try to make sure it is actually a robloxian you are dealing with.

To make sure you are dealing with a humanoid , you will need this:

local h = part.Parent:FindFirstChild("Humanoid")
if h ~= nil then

It is saying if the humanoid exists, then it will clone the GUI.

Make sure to add an end for the if+then

Add this with it: (Don't forget to create the function)

local h = part.Parent:FindFirstChild("Humanoid")
if h ~= nil then

local s = script.Gui:clone()
	s.Parent = game.Players:FindFirstChild(part.Parent.Name).PlayerGui
end

1 comment

0

Someone already answered it. Thanks anyway.

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