Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to change body color using Remote event?

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function()
	local BodyColors = Instance.new("BodyColors")
	if (BodyColors ~= nil) then	
      BodyColors.LeftHand = BrickColor.new("Really black")
      BodyColors.RightHand = BrickColor.new("Really black")
      BodyColors.LeftLowerArm = BrickColor.new("Really black")
      BodyColors.RightLowerArm = BrickColor.new("Really black")
end
end)

I am a new developer. T-T

4 comments

0

you should work on changing the properties of the bodycolor inside someones character, either that or parent it under a character

0

local BodyColors = Instance.new("BodyColors") will never be nil.

0

It could be, someone can easily destroy an instance these days

0

unless Instance.new somehow malfunctions which would never happen

1 answer

✓ Accepted answer

This is a better method, it's usually assumed if you desire to change the body colours of a Character, you work with the Characters BodyParts directly. It would look somewhat like so

Also if we're dealing with Server Passed Events, then we know that an argument will be passed along from the ClientFired giving us their PlayerObject, remember though the Player is always the first argument passed, don't confuse it for another, never forget to reference it.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")

RemoteEvent.OnServerEvent:Connect(function(Player) --// Always the first passed.
   local Character = Player.Character
   if (Character ~= nil) then
      local BodyParts = {}
      for _,BodyPart in ipairs(Character:GetChildren())
         if (BodyPart:IsA("BasePart")) then
            table.insert(BodyParts, BodyPart) --// Give us just the BodyParts of either R15 or R6
         end
      end
      for i = 1,#BodyParts do
         BodyParts[i].BrickColor = BrickColor.new("Really black")
      end
   end
end)

There are definitely different, maybe even simpler ways, but this is the method I know, so I hope this helps you out, Good Luck!

8 comments

0

local Character = Player.Character or Player.CharacterAdded ?? -1

0

Simple mistake, fixed, that was a little unnecessary to downvote, just let me know

0

-1 is still valid this will leak threads. The code can yield on the CharacterAdded event but the player can just leave the game before this event runs.

0

Great, thanks fro the tip, I'll fix that

0

Happy?

0

Yes Happyyyyyyy

0

It wasn't meant for you;) does it work?

0

There is a lot of redundancy in this code but at it will work now.

This discussion is preserved as it was. New answers, comments, and votes are closed.