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

How to Change Part Material upon Contact?

Hello there, I have a part that I want the material to be changed from plastic to neon upon contact with the part, and after one second, the material is changed back to plastic. Here's the script I used. The script is located in the part in the workspace.

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		hit.Material = "Neon"
		wait(1.0)
		hit.Material = "Material"
	end
end)

Please help.

4 comments

0

Does it print an error

0

Yes, it did. Upon touching the part, I get the following error in the output log:

0

Is it supposed to change the hit's material or the bricks material

0

Do you want to change a color of a part, or a player? Because the "hit.Material" is in the common the leg of the player. If you want to change the material of a part, just add a variable like local Part = workspace.blahblah and change the hit to the variable name.

2 answers

✓ Accepted answer

This script changed the material to Neon and after 1 second it changes back to Plastic. Instructions: Insert a "Part" into "Workspace" Insert a "Script" into "Part" that's inside "Workspace" and copy and paste or just type what's below.

db = false

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid")then
		if db == false then
			db = true
			script.Parent.Material = Enum.Material.Neon
			wait(1) 
			script.Parent.Material = Enum.Material.Plastic
			db = false
		end
	end
end)

1 comment

0

Thanks! The part did exactly what I wanted it to do.

Although I have not found an answer, this method I used was able to turn the humanoid into the forcefield material. I am pretty sure humanoid figures can't be materialized. Here is my code

local debounce = false

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		for i,v in pairs(hit.Parent:GetDescendants()) do
			if v:IsA("BasePart") then
				v.Material = Enum.Material.ForceField
			end
		end
	end
end)

You can also use hit.Parent:GetChildren() but hit.Parent:GetDescendants will go through all objects from top to bottom. I can't give a perfect answer to your problem though, but this is a good step to your goal though

1 comment

0

Too complicated to understand tbh bud, at least for me :\

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