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

How do I make a function in which a brick slowly disappears?

I am working on a small project where when a player steps on a brick, a seed slowly becomes transparent. On my last question, I asked why it was not working the way I wanted to, and that is answered. But what was not clear is how to use the "humanoid". So far this is my script:

script.Parent.Touched:connect(function(hit)
	 if hit.Parent:findFirstChild("Humanoid")  then
	for 1, 0 ,-0.01 do 
	game.Workspace.Seed.Transparency = i
	end
end)

Why is nothing happening when I touch the brick? Even after adding "if" and "then".

1 comment

0

Haha, I realized I made one mistake. I forgot to change 'Touch' to 'Touched'. But it's still not working.

2 answers

✓ Accepted answer

An 'Humanoid' object is what makes a model live. We generally check if a model has an humanoid to determine whether it is a character or not.

In this case, you are trying to find an humanoid in the Parent of hit -- the part that touched your script's Parent -- but you don't do anything with the result. FindFirstChild looks for a child object with a specific name and returns it if it exists; otherwise it returns nil.

Since you want to make sure the part that touched your script's Parent is a bodypart of a living character model, you want to check if the humanoid object exists; that is, if FindFirstChild successfully returned an humanoid object or if it returned nil. You can verify this by using a simple if statement.

if hit.Parent:FindFirstChild("Humanoid") then
    -- hit.Parent is a character model.
end

if statements will execute their body if, and only if their condition is anything but nil or false. So, if FindFirstChild returns a Part object, the next block will execute; if it returns nil then nothing will happen.

1 comment

0

Ohh, okay. Now I get it. However, after then, I put the for loop, and nothing is being executed.

script.Parent.Touched:connect(function(hit)
   local Humanoid = hit.Parent:FindFirstChild("Humanoid") 
if Humanoid then
    for 1, 0 ,-0.01 do 
    workspace.Seed.Transparency = i
	wait()
    end
end
end)

2 comments

0

Also is this just one brick or a model full of them?

0

Just one brick model. I tried adding what you wrote, and it's not working.

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