I want to know why it does not turn can collide to off, im using a rig model and inside that model you have the humanoid, the humanoidrootpart and then the body parts, and when I try to loop through them and set the parts to can collide = false it wont work
script:
local remote = game.ReplicatedStorage.RemoteEvent2
remote.OnServerEvent:Connect(function(plr)
local char = plr.Character
local hum = char:FindFirstChild("Humanoid")
local humrp = char:FindFirstChild("HumanoidRootPart")
local standrefrence = game.ReplicatedStorage.Stand
local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://17191838064"
local animtrack = hum:LoadAnimation(anim)
animtrack:Play()
local stand = standrefrence:Clone()
stand.Parent = workspace
local standhum = stand.Humanoid
local standhumrp = stand.HumanoidRootPart
standhumrp.CFrame = humrp.CFrame + Vector3.new(3,4,0)
local standanim = stand.Humanoid:LoadAnimation(anim)
standanim:Play()
local ts = game:GetService("TweenService")
local standtable = stand:GetChildren() do
for i, v in pairs(standtable) do
if v:IsA("Part") then
v.CanCollide = false
end
end
end
end)
Try looping through the descendants, not just the children. Descendants will include everything inside each child.
local remote = game.ReplicatedStorage.RemoteEvent2
remote.OnServerEvent:Connect(function(plr)
local char = plr.Character
if not char then
return
end
local standReference = game.ReplicatedStorage.Stand
local animId = "rbxassetid://17191838064"
local anim = Instance.new("Animation")
anim.AnimationId = animId
local animTrack = char.Humanoid:LoadAnimation(anim)
animTrack:Play()
local stand = standReference:Clone()
stand.Parent = workspace
local standHum = stand.Humanoid
local standHumRP = stand.HumanoidRootPart
standHumRP.CFrame = char.HumanoidRootPart.CFrame + Vector3.new(3, 4, 0)
local standAnim = standHum:LoadAnimation(anim)
standAnim:Play()
for _, part in ipairs(stand:GetDescendants()) do
if part:IsA("BasePart") then
part.CanCollide = false
end
end
end)
local parts = {}
for _, part in ipairs(stand:GetDescendants()) do
if part:IsA("BasePart") then
table.insert(parts, part) --collect parts into an array
end
end
for _, part in ipairs(parts) do --iterate over the array of parts
part.CanCollide = false
part.Reflectance = 0.5 --example
part.Transparency = 0.5 --example
end