Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to Change Part Material upon Contact?

Asked by 3 years ago

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.

0
Does it print an error MediaHQ 53 — 3y
0
Yes, it did. Upon touching the part, I get the following error in the output log: Kaexotix 57 — 3y
0
Is it supposed to change the hit's material or the bricks material MediaHQ 53 — 3y
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. BlackFateX 19 — 3y

2 answers

Log in to vote
1
Answered by 3 years ago

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)
0
Thanks! The part did exactly what I wanted it to do. Kaexotix 57 — 3y
Ad
Log in to vote
0
Answered by
MediaHQ 53
3 years ago

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

0
Too complicated to understand tbh bud, at least for me :\ Nitrolux200 62 — 3y

Answer this question