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

Why is this unable to change the material of the player?

Asked by 5 years ago
Edited 5 years ago

I have a script for a crystal that when touched by the player it slowly turns the player into the crystal. It works up until changing the material.

local debounce = false

local colorChange = {
    {'Head', 'Mid Gray', 'Granite'};
    {'Torso', 'Mid Gray', 'Granite'};
    {'Left Arm', 'Mid Gray', 'Granite'};
    {'Right Arm', 'Mid Gray', 'Granite'};
    {'Left Leg', 'Mid Gray', 'Granite'};
    {'Right Leg', 'Mid Gray', 'Granite'};
}

script.Parent.Touched:Connect(function (hit)
    if debounce == true then return end
    debounce = true
    wait(2)
    local humanoid = hit.Parent:FindFirstChild('Humanoid')
    if humanoid then
        for _,v in pairs(colorChange) do
            humanoid.Parent[v[1]].BrickColor = BrickColor.new(v[2])
            humanoid.Parent[v[1]].Material = Enum.Material(v[3])
            wait(0.3)
        end
        wait(3)
        debounce = false
    else
        debounce = false
    end
end)

The output says:

Workspace.SCPs.SCP-409.Contagion [New]:20: attempt to call field 'Material' (a userdata value)

What does this mean and how do I fix it?

1 answer

Log in to vote
1
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
5 years ago

You need to use square parenthesis instead of normal ones.

humanoid.Parent[v[1]].Material = Enum.Material[v[3]]
0
Thank you! BlauKitten 88 — 5y
Ad

Answer this question