I’m trying to create a customization feature with a custom character and custom parts. There is a body part named “Body” that I want to swap. I was able to destroy the body using body:Destroy(), but I’m not able to change it for some reason.
local allBodies = ReplicatedStorage:WaitForChild("Customization"):WaitForChild("Body"):GetChildren()
local body = char:WaitForChild("Body")
body = allBodies[1] -- supposed to swap body
How can I swap the body part?
1 Like
All you’re doing is changing the value of the variable body
, but you’re not actually doing anything.
I’ll give you an example.
local number = 1
number = 2
This doesn’t make one equal two, it just changes the variable called number
from one to two.
As for the rest of the code, it’s too hard to write everything for you.
What you’d want to do is something like this (sorry if this is confusing):
local Player = -- the player (if this a local script put 'game.Players.LocalPlayer' here)
local Character = Player.Character
local Old_Body = -- the body part that youre swapping out
local New_Body = -- the body part that youre swapping in
-- destroy the old body part
Old_Body:Destroy()
-- put the new body part into your character
New_Body.Parent = Character
-- Then you'd need to position the new body part and
-- weld/connect it to your character so it stays with it
That’s basically what something like this would look like.
Awesome thanks! I was able to swap and weld the part in the correct location.