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!
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