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

Help with a skin color editing script. No errors, but it still doesn't work?

Asked by 4 years ago

(((I'm a big noob to scripting, so bear with me.)))

I'm having trouble creating a skin color GUI for an avatar editor. What I want to do is have the player input a 0-255 value into 3 separate TextBoxes for R G and B values, then press a TextButton that fires a RemoteEvent which applies the color to the character via BodyColors.

I've tried a lot of things, and my most recent code iteration isn't showing any errors. However, it still isn't working.

It should bear mentioning that LoadCharacterAppearance is false, though enabling it doesn't seem to change anything.

Here's the Script i'm using, which is in ServerScriptService:

local textboxR = game.StarterGui.ScreenGui.Frame1.SkinColorR
local textboxG = game.StarterGui.ScreenGui.Frame1.SkinColorG
local textboxB = game.StarterGui.ScreenGui.Frame1.SkinColorB
textboxR.FocusLost:Connect(function()
    rvalue = tonumber(textboxR.Text)/256
end)
textboxG.FocusLost:Connect(function()
    gvalue = tonumber(textboxG.Text)/256
end)
textboxB.FocusLost:Connect(function()
    bvalue = tonumber(textboxB.Text)/256
end)
function SetSkinColor(r, g, b)
    local Button = game.StarterGui.ScreenGui.Frame1.TextButton
    local char = game.Players.LocalPlayer.Character
    local bodyColors = {'HeadColor3', 'Torso3', 'RightArmColor3', 'LeftArmColor3', 'RightLegColor3','LeftLegColor3'}
    local bodyColor = Color3.new(r, g, b)
    if (r > 1 or r < 0) or (g > 1 or g < 0)or (b > 1 or b < 0)
    then
    print("Color out of valid range!!!")
    else
    for _,color in pairs(bodyColors) do
        char["Body Colors"][color] = Color3.new(r, g, b)
    end
    end
end
game.ReplicatedStorage.Events.SkinColor.OnServerEvent:Connect(rvalue, gvalue, bvalue)

and here is the LocalScript I have in the TextButton:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SetSkinColorEvent = game.ReplicatedStorage.Events.SkinColor

local function SetSkinColor()
    SetSkinColorEvent:FireServer()
end

game.StarterGui.ScreenGui.Frame1.TextButton.MouseButton1Click:Connect(SetSkinColor)

Any and all help would be appreciated, because I'm still new to this. Thanks in advance. :))

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Hmm. I found 4 problems with your script. You're using LocalPlayer in a server script, and only LocalScripts can use game.Players.LocalPlayer. The second problem is if (r > 1 or r < 0) or (g > 1 or g < 0)or (b > 1 or b < 0) then print("Color out of valid range!!!"). RGB values go up to 255. HSV values are the ones that go from 0% - 100%, or 0 - 1. Third problem, OnServerEvent returns a player variable, and you put rvalue where the player variable is supposed to go. Edit: Forgot to say, you are also trying to get the value of a textbox in StarterGui. What you're supposed to do is access the player's gui in game.Players.<playername>.PlayerGui, or in a LocalScript, game.Players.LocalPlayer.PlayerGui.

Script:

function SetSkinColor(player, r, g, b)
    local Button = game.StarterGui.ScreenGui.Frame1.TextButton
    local char = player.Character
    local bodyColors = {'HeadColor3', 'Torso3', 'RightArmColor3', 'LeftArmColor3', 'RightLegColor3','LeftLegColor3'}
    local bodyColor = Color3.new(r, g, b)
    if (r > 255 or r < 0) or (g > 255 or g < 0)or (b > 255 or b < 0)
    then
    print("Color out of valid range!!!")
    else
    for _,color in pairs(bodyColors) do
        char["Body Colors"][color] = Color3.new(r, g, b)
    end
    end
end
game.ReplicatedStorage.Events.SkinColor.OnServerEvent:Connect(player, rvalue, gvalue, bvalue)

LocalScript:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SetSkinColorEvent = game.ReplicatedStorage.Events.SkinColor

local textboxR = game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame1.SkinColorR
local textboxG = game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame1.SkinColorG
local textboxB = game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame1.SkinColorB

local function SetSkinColor()
    SetSkinColorEvent:FireServer(textboxR.Text, textboxG.Text, textboxB.Text)
end

game.StarterGui.ScreenGui.Frame1.TextButton.MouseButton1Click:Connect(SetSkinColor)
0
Ok, I dealt with all the issues except the first one. Assuming I only want this to apply to the player who presses the button, what would I do for that? Would I have to split it up into both a Script and a LocalScript? obsoletechicken43 0 — 4y
Ad

Answer this question