Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Lua 为什么Color3值更改为错误的数字?_Lua_Roblox - Fatal编程技术网

Lua 为什么Color3值更改为错误的数字?

Lua 为什么Color3值更改为错误的数字?,lua,roblox,Lua,Roblox,我正在努力使它成为玩家可以制作CUSOMAT的地方,但当它设置Color3值时,它会变成一个比正常参数大得多的数字。例如,当脚本尝试将值设置为(255,0,0)时,它将转到(65025,0,0)。这是代码,我做错了什么 script.Parent.MouseButton1Click:Connect(function() local Player = script.Parent.Parent.Parent.Parent.Parent.Parent print("CustomChan

我正在努力使它成为玩家可以制作CUSOMAT的地方,但当它设置Color3值时,它会变成一个比正常参数大得多的数字。例如,当脚本尝试将值设置为(255,0,0)时,它将转到(65025,0,0)。这是代码,我做错了什么

script.Parent.MouseButton1Click:Connect(function()
    local Player = script.Parent.Parent.Parent.Parent.Parent.Parent
    print("CustomChanged")
    if script.Parent.Value.Value == Color3.new(0,0,0) then
        script.Parent.Value.Value = Color3.new(255,255,255)
        Player.Skins.Custom.Head.Color.Value = script.Parent.Value.Value
        script.Parent.Parent.Parent.Character.Custom.Head.Color = script.Parent.Value.Value
        script.Parent.Frame.BackgroundColor3 = script.Parent.Value.Value
    elseif script.Parent.Value.Value == Color3.new(255,255,255) then
        script.Parent.Value.Value = Color3.new(255,0,0)
        Player.Skins.Custom.Head.Color.Value = script.Parent.Value.Value
        script.Parent.Parent.Parent.Character.Custom.Head.Color = script.Parent.Value.Value
        script.Parent.Frame.BackgroundColor3 = script.Parent.Value.Value
    elseif script.Parent.Value.Value == Color3.new(255,0,0) then
        script.Parent.Value.Value = Color3.new(255, 136, 0)
        Player.Skins.Custom.Head.Color.Value = script.Parent.Value.Value
        script.Parent.Parent.Parent.Character.Custom.Head.Color = script.Parent.Value.Value
        script.Parent.Frame.BackgroundColor3 = script.Parent.Value.Value
    elseif script.Parent.Value.Value == Color3.new(255, 136, 0) then
        script.Parent.Value.Value = Color3.new(255,255,0)
        Player.Skins.Custom.Head.Color.Value = script.Parent.Value.Value
        script.Parent.Parent.Parent.Character.Custom.Head.Color = script.Parent.Value.Value
        script.Parent.Frame.BackgroundColor3 = script.Parent.Value.Value
    elseif script.Parent.Value.Value == Color3.new(255,255,0) then
        script.Parent.Value.Value = Color3.new(0,255,0)
        Player.Skins.Custom.Head.Color.Value = script.Parent.Value.Value
        script.Parent.Parent.Parent.Character.Custom.Head.Color = script.Parent.Value.Value
        script.Parent.Frame.BackgroundColor3 = script.Parent.Value.Value
    elseif script.Parent.Value.Value == Color3.new(0,255,0) then
        script.Parent.Value.Value = Color3.new(0,255,255)
        Player.Skins.Custom.Head.Color.Value = script.Parent.Value.Value
        script.Parent.Parent.Parent.Character.Custom.Head.Color = script.Parent.Value.Value
        script.Parent.Frame.BackgroundColor3 = script.Parent.Value.Value
    elseif script.Parent.Value.Value == Color3.new(0,255,255) then
        script.Parent.Value.Value = Color3.new(0,0,255)
        Player.Skins.Custom.Head.Color.Value = script.Parent.Value.Value
        script.Parent.Parent.Parent.Character.Custom.Head.Color = script.Parent.Value.Value
        script.Parent.Frame.BackgroundColor3 = script.Parent.Value.Value
    elseif script.Parent.Value.Value == Color3.new(0,0,255) then
        script.Parent.Value.Value = Color3.new(255,0,255)
        Player.Skins.Custom.Head.Color.Value = script.Parent.Value.Value
        script.Parent.Parent.Parent.Character.Custom.Head.Color = script.Parent.Value.Value
        script.Parent.Frame.BackgroundColor3 = script.Parent.Value.Value
    elseif script.Parent.Value.Value == Color3.new(255,0,255) then
        script.Parent.Value.Value = Color3.new(255,0,205)
        Player.Skins.Custom.Head.Color.Value = script.Parent.Value.Value
        script.Parent.Parent.Parent.Character.Custom.Head.Color = script.Parent.Value.Value
        script.Parent.Frame.BackgroundColor3 = script.Parent.Value.Value
    elseif script.Parent.Value.Value == Color3.new(255,0,205) then
        script.Parent.Value.Value = Color3.new(0,0,0)
        Player.Skins.Custom.Head.Color.Value = script.Parent.Value.Value
        script.Parent.Parent.Parent.Character.Custom.Head.Color = script.Parent.Value.Value
        script.Parent.Frame.BackgroundColor3 = script.Parent.Value.Value
    end
end)

您应该改用
Color3.fromRGB(255,0,0)

如果使用
Color3.new(…)
它需要0到1的颜色值

因此,由于在资源管理器中,它显示255倍于该值,因此您将看到255*255=65025

顺便说一下:

如果要避免对每种颜色重复相同的代码,可以执行以下操作:

-- store all colors that you want to use in an array
local colors = {
    Color3.fromRGB(0,0,0),
    Color3.fromRGB(255,255,255),
    Color3.fromRGB(255,0,0),
    Color3.fromRGB(0,255,0),
    Color3.fromRGB(0,0,255)
}

-- keep track of current color
currentColor = 1

script.Parent.MouseButton1Click:Connect(function()
    if (currentColor == #colors) then                           -- it current color is the last one in the array, go back to zero
        currentColor = 0
    end
    currentColor = currentColor + 1                             -- increment current color by one

    script.Parent.BackgroundColor3 = colors[currentColor]       -- (here you do whatever you want to do with the color)
end)