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

I have a morth maker that worked and for some reason it stopped working. why?

I have a morth script and the idea is that it sticks different parts on your body and makes the morth, but your body turn invisible. It worked perfectly fine but it stopped working for some reason and I am getting an error in this script:

function onTouch(part) 
local human = part.Parent:findFirstChild("Humanoid") 
if human ~= nil then 
part.Parent:findFirstChild("Head").Transparency = 1
part.Parent:findFirstChild("Torso").Transparency = 1
part.Parent:findFirstChild("Left Arm").Transparency = 1
part.Parent:findFirstChild("Right Arm").Transparency = 1
part.Parent:findFirstChild("Left Leg").Transparency = 1
part.Parent:findFirstChild("Right Leg").Transparency = 1
if part.Parent:findFirstChild("Head"):findFirstChild("face") == nil then return end
part.Parent:findFirstChild("Head"):findFirstChild("face"):remove()
if part.Parent:findFirstChild("Torso"):findFirstChild("roblox") == nil then return end
part.Parent:findFirstChild("Torso"):findFirstChild("roblox"):remove()
end 
end 
script.Parent.Touched:connect(onTouch) 

THE ERROR: "Workspace.Morph maker.Floating Head.Script:7: attempt to index a nil value"

Could anyone help me? As I said it DID work. For some reason it stopped.

1 answer

✓ Accepted answer
local Players = game:GetService("Players")

function TOUCHED(hit)
	if hit then 
		if Players:FindFirstChild(hit.Parent.Name) then 
			local player = Players:FindFirstChild(hit.Parent.Name)

			for _, v in pairs(player.Character:GetChildren()) do 
				if v:IsA("BasePart") then 
					v.Transparency = 1
					v:ClearAllChildren()
				end
			end

		end
	end
end

script.Parent.Touched:connect(TOUCHED)

5 comments

0

Explain why this code works and how this code works so that he and others like him wouldn't make the same mistake in the future. You could also explain why you've tabbed your code how you did now so that he could do the same in the future. We're teaching people how to code, not doing work for them.

0

basically this gets the player by checking if 'hit.Parent.Name' is in Players. Next, I used a loop (for i, v in pairs) to get objects in the player's character. After that, it filters if the object is a part or not . Lastly, the script sets the part(s) transparency to 1 (so its not visible) and clears any children in the part (faces, decals, t shirts.. yea)

0

oh yes very important part! last line links the Touched event to the part. dont forget that!111

0

Thank you. :) I have some big plans, hope this will help me in the future. Right now its all good.

1

No problem, good luck!

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