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

Why is it not setting the Players skin colour? (Color)

Asked by 3 years ago
Edited 3 years ago
Gate = script.Parent

local player = game:GetService("Players").LocalPlayer

Gate.Touched:Connect(function(hit)

    wait()

    if hit and hit.Parent:FindFirstChild("Humanoid") then

        local head = player.Head

        local ltorso = player.LowerTorso
        local utorso = player.UpperTorso

        local lleftarm = player.LeftLowerArm
        local uleftarm = player.LeftUpperArm

        local lrightarm = player.RightLowerArm
        local urightarm = player.RightUpperArm

        local lleftleg = player.LeftLowerLeg
        local uleftleg = player.LeftUpperLeg

        local lrightleg = player.RightLowerLeg
        local urightleg = player.RightUpperLeg

        local lhand = player.LeftHand
        local rhand = player.RightHand

        local lfoot = player.LeftFoot
        local rfoot = player.RightFoot

        wait(1)

        lhand.Colour = {255, 255, 255} -- Imagine I've set everything to "255, 255, 255", I was just using "lhand" to test

    end

end)

This is a script I've got that should change the Player's skin colour once touched a part, it doesn't work and in the output I get ' attempt to index nil with "Head" ', can anyone help please?

2 answers

Log in to vote
0
Answered by 3 years ago

Theres a couple things wrong with this, first its in a server script and when it gets touched by anything with a humanoid itll change everyones color, 2nd you cant get local player in a server script, and third the character limbs are located in localplayer.Character not in the LocalPlayer and fourth your not setting the color right.

Gate = script.Parent

local players = game:GetService("Players")

Gate.Touched:Connect(function(hit)
    if hit and hit.Parent:FindFirstChild("Humanoid") then
        local Char = hit.parent --this contains all the character limbs
        local Name = Char.Name

        local plr = players[Name] --the plr isnt required here but this is how you would get it anyway

           --creating variables for components inside of a group manually isnt very efficient 

        wait(1)

        for i,v in pairs(Char:GetChildren()) do --creating table with the Characters cilds(components inside the Character)

            if v:IsA("MeshPart") then --if the child is a meshpart which the limbs are then..

                v.Color = Color3.new(255,255,255) --change the meshparts color to whatever you set

            end
        end

    end

end)

also i made it shorter, hopefully this helps

Ad
Log in to vote
0
Answered by 3 years ago
Gate = script.Parent

local player = game:GetService("Players").LocalPlayer

Gate.Touched:Connect(function(hit)

    wait()

    if hit and hit.Parent:FindFirstChild("Humanoid") then
        local player = hit.Parent -- player was not equal to anything
        local head = player.Head

        local ltorso = player.LowerTorso
        local utorso = player.UpperTorso

        local lleftarm = player.LeftLowerArm
        local uleftarm = player.LeftUpperArm

        local lrightarm = player.RightLowerArm
        local urightarm = player.RightUpperArm

        local lleftleg = player.LeftLowerLeg
        local uleftleg = player.LeftUpperLeg

        local lrightleg = player.RightLowerLeg
        local urightleg = player.RightUpperLeg

        local lhand = player.LeftHand
        local rhand = player.RightHand

        local lfoot = player.LeftFoot
        local rfoot = player.RightFoot

        wait(1)

        lhand.Color = Color3.fromRGB(255, 255, 255) -- Spelled Color Wrong and did not format Color Correctly

    end

end)
0
You have to spell color the American way lleyton1030 2 — 3y
0
i'm probably missing something but it still doesnt work, the players colour is not changing, and annoyingly the output has nothing to say. Does this have to be in a localscript by any chance? WeaponisedPenguins 97 — 3y

Answer this question