For a game I’m trying to make, i need to know how to:
Search the player’s model in the Workspace
Find anything with the class name “CharacterMesh”
Delete it from the player’s model so the player looks blocky.
Code:
function changePlayerBodyType(player)
local player2 = workspace:FindFirstChild(player.Name)
if player2:FindFirstChild("CharacterMesh") then
for i,v in pairs(player2:GetChildren("CharacterMesh")) do
v:Destroy()
end
end
end
game.Players.PlayerAdded:Connect(changePlayerBodyType)
you can try using the Humanoid Description System instead, just create a humanoid description with the properties you need and apply that to the players.
I’m not entirely sure why you added a string on the parameters of :GetChildren("CharacterMesh"), :GetChildren() only returns the array of the instance’s children that its function is connected to and has no parameters available.
I would do it like this:
function changePlayerBodyType(player)
for i, v in pairs(player.Character:GetChildren()) do
if v:IsA("CharacterMesh") then -- checks if its a character mesh type
v:Destroy() -- destroys it if it is
end
end
end
game.Players.PlayerAdded(changePlayerBodyType)
I apologize if the indentation isn’t good enough since I am typing this on mobile.
The way you typed it out didn’t work, but I modified the text and it worked. Thanks anyway
What I used:
function changePlayerBodyType(player)
local player2 = workspace:WaitForChild(player.Name)
for i,v in pairs(player2:GetChildren()) do
if v:IsA("CharacterMesh") then
v:Destroy()
end
end
end
game.Players.PlayerAdded:Connect(changePlayerBodyType)
It probably couldn’t find the character but either way I was typing this on mobile and didn’t check whether it would work in studio. I’m glad I’ve helped you regardless!