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

How do you change the body color of a player, with a local script?

Asked by 6 years ago
Edited 6 years ago

Hi, I tried making a script that changes a players color when they click F. But for some reason this error keeps on showing up:

18:53:10.311 - ContextActionService: Unexpected error while invoking callback: Players.turbomegapower12345.PlayerGui.ZeusPowers:42: attempt to index global 'RightArmColor' (a nil value)

Here is my script:

local player = game.Players.LocalPlayer
local character = player.CharacterAdded:Wait() 
local head = character:WaitForChild("Head")

local Humanoid = character:WaitForChild("Humanoid")
local torso = character.UpperTorso
local mouse = player:GetMouse()

local bodycolors = character:WaitForChild("Body Colors")


local Workspace = game.Workspace


local target



local God = player.PlayerGui.ChooseCharacter.God
--BREAKLINE--

local function onKeyPress(actionName, userInputState, inputObject)
    target = mouse.Target
    if userInputState == Enum.UserInputState.Begin then
    if inputObject.KeyCode.Name =="T" then
        if God.Value =="Zeus" then
            game:GetService("Chat"):Chat(player.Character.Head, "MASTERBOLT!","Blue")
            local tool = game.Workspace.BetaBolt:Clone()
            character.Humanoid:EquipTool(tool)
            wait(5)
            tool:Destroy()

        end
    end



       if inputObject.KeyCode.Name =="F" then
        if God.Value =="Zeus" then
        game:GetService("Chat"):Chat(player.Character.Head, "FEEL THE POWER OF A TRUE GOD!","Blue")
        Humanoid.HipHeight = 20
        bodycolors.RightArmColor = ("Dark blue")

        wait(6)
        --end of power--

        Humanoid.HipHeight = 1.35
        end
    end

    if inputObject.KeyCode.Name =="Q" then
        if God.Value == "Zeus" then
            game:GetService("Chat"):Chat(player.Character.Head, "LIGHTNING DASH!","Blue")
            head.CFrame = head.CFrame * CFrame.new(0,0,-50)
        else
            print("FAIL LIGHTNING DASH")

        end
    end


    if inputObject.KeyCode.Name =="E" then
         if God.Value == "Zeus" then  
            game:GetService("Chat"):Chat(player.Character.Head, "THUNDER!","Blue")
            local damage = game.Workspace.Damage:Clone()
            local Thunder = Instance.new("Part")
            Thunder.Name = ("ThunderBolt")
            local mesh = Instance.new("SpecialMesh",Thunder)
            mesh.MeshId = "rbxassetid://978945957"
            mesh.TextureId = "rbxassetid://978945981"
            Thunder.Anchored = true
            Thunder.Orientation = Vector3.new(0,0,0)
            mesh.Scale = Vector3.new(5,20,15)
            damage.Position = Vector3.new(mouse.hit.x,mouse.hit.y,mouse.hit.z)
            damage.Parent = workspace
            Thunder.Position = Vector3.new(mouse.hit.x,mouse.hit.y,mouse.hit.z)
            Thunder.Parent = workspace
            wait(1)
            damage:Destroy()
            Thunder:Destroy()
                    else
            print("FAIL THUNDERBOLT")
    end


        end
    end
end

game:GetService("ContextActionService"):BindAction(
    "keyPress", 
    onKeyPress, 
    false, 
    Enum.KeyCode.Q,
    Enum.KeyCode.E,
    Enum.KeyCode.F,
    Enum.KeyCode.T
)
0
Does any1 know a solution? turbomegapower12345 48 — 6y

2 answers

Log in to vote
0
Answered by
aazkao 787 Moderation Voter
6 years ago
Edited 6 years ago

Your syntax is wrong, use this

bodycolors.RightArmColor = BrickColor.new("Dark blue")
Ad
Log in to vote
0
Answered by 6 years ago

you can use a for i,v in pairs() loop which can change the players limbs and bodypart colours like this:

local bodyparts = game.Players.LocalPlayer.Character:GetChildren()

for _,body in pairs(bodyparts) do
    if body:IsA("Part") then -- checks if its a part
        body.BrickColor = BrickColor.new("Dark blue") -- changes colour
    end
end

but if u want it to change a certain bodypart, like u only did the rightarm you can do this:

local bodyparts = game.Players.LocalPlayer.Character:GetChildren()

for _,body in pairs(bodyparts) do
    if body.Name = "RightArm" then -- checks if the name is "RightArm"
        body.BrickColor = BrickColor.new("Dark blue") -- changes colour
    end
end
0
doesnt work turbomegapower12345 48 — 6y

Answer this question