im producing a simulator and i need help making a scripthow might i change a body component color through a textbutton?example of what i would choose to achieve: change torso shade to blue


This is fairly simple come do, very first of all: is your video game R6 of R15? and also which body part would you choose to offer a color?


Local manuscript in the text button:

script.Parent.MouseClick:Connect(function() neighborhood char = YOUR_PLAYER_HERE.Character if char:FindFirstChild("Humanoid") climate if char.Humanoid.Health >=1 climate char<"Left Arm">.Color = Color3.FromRGB(255, 255, 255) finish endend)Replace YOUR_PLAYER_HERE by the player.

You are watching: How to change body color in roblox

Exemple to get the player:

Random player

Local plrs = game.Playerslocal RandomPlayerChosen = math.random(1, #plrs)

You (Local Player)

Local Player = game.Players.LocalPlayer

Target player

local TargetPlayer = game.Players.JustABaconHair1234

Exemple that R15 body parts

*


IggyDev (Iggy) march 4, 2021, 10:30pm #4

This has an issue, this only alters the body color for the client, due to the fact that it’s in a regional script, other civilization won’t watch this. You would have to make use of RemoteEvents in bespeak to do this work.

Also, mouseclick is because that clickdetectors, in the instance of a button, you use mousebutton1click.

This have to work:

Create a localscript in the buttonStart by adding a localscript in your button, let’s now script it.

First that all, we want to finding if a player has pressed the button, we deserve to do this by using a mousebutton1click event.

script.Parent.MouseButton1Click:Connect(function()end)This event would fire when the player has clicked the button, us may additionally want to add a .3 second cooldown, to avoid the script from breaking.

We can do this by do a new variable called CoolDown, us will set this come false on standard. After ~ that, we will examine if the CoolDown is on false, if so, the script continue’s, if the CoolDown is on true, the doesn’t run the code.

We additionally have to set the CoolDown to true as soon as the player clicked, climate wait 0.3 seconds before we collection it come false again.

Like this:

local coolDown = falsescript.Parent.MouseButton1Click:Connect(function() -- The player has actually clicked the switch if coolDown == false climate -- If the cooldown is false, run the code coolDown = true -- set the cooldown to true wait(.3) -- Wait 0.3 secs coolDown = false -- collection the coolDown come false again endend)Great! The last point to execute is come fire the remote occasion to the server, so us can adjust the player’s color, we’re firing an event to the server, since if we adjust the players shade on the client, just the customer will see the color change, and not the other players.

So, walk to ReplicatedStorage and add a RemoteEvent, contact this event “BodyColorEvent”

Now, in our password we will certainly paste the following:

game.ReplicatedStorage.BodyColorEvent:FireServer()

We’re excellent on the client side! currently we deserve to script on the server side. An initial of all, include a script into ServerScriptService, friend may speak to this whatever you want.

Now, we will certainly detect when the occasion has to be fired, kind this code right into your script.

game.ReplicatedStorage.BodyColorEvent.OnServerEvent:Connect(function() end)This code will certainly get connected once the BodyColorEvent has actually been fired native the neighborhood script.

Now, us will get the player and also the player’s character.

game.ReplicatedStorage.BodyColorEvent.OnServerEvent:Connect(function(player) -- The debate "player" is the player that obtained the event, for this reason the player that fired the event from the local script regional character = player.Character -- The player"s character if character then -- If the player isn"t death and also the character has been loaded in endend)With this, we first of all obtain the player through the very first argument, then we can acquire the player’s personality by that in addition to checking if the character is actually there.

Now, we have the right to finally adjust the player’s color.

character<"LowerTorso">.BrickColor = BrickColor.new("Really blue")character<"UpperTorso">.BrickColor = BrickColor.new("Really blue")

Assuming your game kind is R15 and also you would choose to adjust the torso’s color, you have actually to change the lower and also upper torso’s color, when you usage R6, you can just say “Torso”.

If friend would choose to readjust the color, change the brickcolor come a different brickcolor, if friend would like to give a different body component a various color, adjust the bodypart whereby I for now put LowerTorso and also UpperTorso.

See more: I Ll Never Forgive You Quotes, Top 25 Never Forgive Quotes (Of 96)

If girlfriend followed every one of these steps, this have to be your last code:

LocalScript

local coolDown = falsescript.Parent.MouseButton1Click:Connect(function() -- The player has clicked the button if coolDown == false climate -- If the cooldown is false, run the password coolDown = true -- collection the cooldown come true game.ReplicatedStorage.BodyColorEvent:FireServer() wait(.3) -- Wait 0.3 secs coolDown = false -- collection the coolDown come false again endend)ServerScript

game.ReplicatedStorage.BodyColorEvent.OnServerEvent:Connect(function(player) -- The debate "player" is the player that obtained the event, therefore the player who fired the occasion from the local script regional character = player.Character -- The player"s character if character climate -- If the player isn"t death and the character has actually been loaded in character<"LowerTorso">.BrickColor = BrickColor.new("Really blue") character<"UpperTorso">.BrickColor = BrickColor.new("Really blue") finish end)Note: i didn’t check this yet, since I’m top top a laptop there is no studio on it, if girlfriend have any errors, feel free to allow me know so ns can assist you through it.