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

How do I change the color of a custom character's torso when bought using a Gui?

Asked by 5 years ago
Edited 5 years ago

I made a Custom Character (Placing a StarterCharacter and StarterHumaniod in StarterPlayer) and I'm trying to have it so when a player clicks on a button their torso will change to the color they choose. (If they choose the red button their torso will turn red) They can only do this if they have enough coins though.

local player = game.Players.LocalPlayer
local leaderboard = player:WaitForChild("leaderstats")
local button = script.Parent
local price = button:WaitForChild("Price")
local color = button:WaitForChild("ColorName")

button.MouseButton1Click:Connect(function()
    if leaderboard.Coins.Value >= price.Value then
    game.Workspace.player.Torso.BrickColor = BrickColor.new("Purple") 
    script.Parent.MouseButton1Down:connect(clicked)
    end
end

A quick overview of my script: the second line accesses the leaderboard and stats (where the players coins are). The third fourth and fifth lines access the button and the values that are next to the button. What it is supposed to do is when the button is clicked the script sees if the player has enough coins and than goes into the player and changes the Torso to a certain color. (The player is not supposed to lose coins when they purchase because I am changing the stats to levels at some point) I don't know why it isn't changing the Torso color of the player. If anyone can help that would be great!

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

The only way that script could have had an error is if you were in filtering enabled, so I updated it to be compatible with FE:

--Make a remote event named ChangeTorso

local player = game.Players.LocalPlayer
local leaderboard = player:WaitForChild("leaderstats")
local button = script.Parent
local price = button:WaitForChild("Price")
local color = button:WaitForChild("ColorName")

button.MouseButton1Click:Connect(function()
    if leaderboard.Coins.Value >= price.Value then
        game.ReplicatedStorage.ChangeTorso:FireServer(player.Name, color) 
    end
end

Put this server script in ServerScriptService:

game.ReplicatedStorage.ChangeTorso.OnServerEvent:Connect(function(player)
    if workspace:FindFirstChild(player.Name) then
        if workspace[player.Name]:FindFirstChild("Torso") then
            workspace[player.Name].Torso.BrickColor = BrickColor.new(color)
        end
    end
end)

Hope I helped!

-Cmgtotalyawesome

0
Can I add you on team create so you can help me? Because for some reason it is not working and I'm probably just messing it up. tawk1215 47 — 5y
0
@tawk1215 sure cmgtotalyawesome 1418 — 5y
Ad

Answer this question