Hello everyone, I am making this post because I have run into an issue that I don’t know how to solve. Basically, I am getting some of the player’s character, and I am spawning them in. (Meaning that they are preset so I can’t do that) What I am doing is when the player interacts with their friends, they take a body part. The problem with this, is if they have an accessory like a shirt, hat, etc., it doesn’t tween with it. Any solutions?
Can I get a chance to see your code?
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local player = Players.LocalPlayer
local module = require(ReplicatedStorage.ModuleScripts.SpawnNPC)
local NPCFolder = game.Workspace:WaitForChild("NPC")
local friendId = module.GetFriendsList(player.UserId)
local randomFriendId = friendId[1][math.random(1,friendId[2])]
NPCFolder.ChildAdded:Connect(function(npc)
npc.HumanoidRootPart.ProximityPrompt.Triggered:Connect(function()
local amountOfLimbs = npc:GetAttribute("AmountOfLimbs")
local limbValue = npc:GetAttribute("LimbValue")
if amountOfLimbs >= 1 then
print("Collecting limb")
npc:SetAttribute("AmountOfLimbs",amountOfLimbs - 1)
local tableOfLimbs = {}
for i, v in pairs(npc:GetChildren()) do
if v:IsA("Part") and v.Name ~= "HumanoidRootPart" then
table.insert(tableOfLimbs,v)
end
end
local limb = tableOfLimbs[math.random(1, #tableOfLimbs)]
limb.Parent = game.Workspace
local goal = {}
goal.CFrame = player.Character.HumanoidRootPart.CFrame
local tweenInfo = TweenInfo.new(
2, -- Time
Enum.EasingStyle.Sine, -- EasingStyle
Enum.EasingDirection.Out, -- EasingDirection
0, -- RepeatCount (when less than zero the tween will loop indefinitely)
false, -- Reverses (tween will reverse once reaching it's goal)
0 -- DelayTime
)
local tween = TweenService:Create(limb, tweenInfo, goal)
tween:Play()
task.wait(1)
limb:Destroy()
--Do remote evnet thing here
if amountOfLimbs <= 0 then
npc:Destroy()
end
end
end)
end)
module.Spawn(1, friendId, 5)
Alright, so there is a way to get the accessories on a player, mostly all of them.
What I would recommend doing to get the accessories on a player is the same thing you did with the limbs, store them into a table.
Here is some sample code;
local accessoriesTable = {}
for _, accys in pairs(char:GetChildren()) do
if accys:IsA("Accessory") then
if accys.AccessoryType == Enum.AccessoryType.Face or accys .AccessoryType == Enum.AccessoryType.Hair or accys .AccessoryType == Enum.AccessoryType.Hat or accys .AccessoryType == Enum.AccessoryType.Neck then
local accesshandle = accys:WaitForChild("Handle")
table.insert(accessoriesTable,accesshandle)
end
end
end
local accessory = accessoriesTable[math.random(1, #accessoriesTable)]
And then, create a tween for the accessories;
local accessgoal = {}
accessgoal.CFrame = player.Character.HumanoidRootPart.CFrame
local accesstween = TweenService:Create(accessory, tweenInfo, accessgoal )
accesstween:Play()
task.wait(1)
accessory.Parent:Destroy()
If this idea doesn’t at least help, then I have no clue.
Also, Im not too sure about tweening shirts, seems too difficult to do.
Forgot to mention, when you are trying to get all the accessories inside of a character, make sure the for loop for getting accessories is in a ServerScript because when it is ran on a ClientScript, for some reason it just doesn’t work.
Your gonna have to do extra work to get the character and then less work to get the character’s accessories though.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.