#trying to change player part's collision group

1 messages · Page 1 of 1 (latest)

viral field
#

already tried this with a regular part, and it worked.

script.Parent.Touched:Connect(function(part)
    if part.Parent:FindFirstChild("Humanoid") then
        part.Parent["Left Leg"].CollisionGroup = "buffer"
        part.Parent["Right Leg"].CollisionGroup = "buffer"
        task.wait(1)
        part.Parent["Left Leg"].CollisionGroup = "Default"
        part.Parent["Right Leg"].CollisionGroup = "Default"
    end
end)

local ps = game:GetService("PhysicsService")
scenic turtle
#

you don't know how to do it to a player?

viral field
#

wdym

#

if ur talking abt what i said there, i tried this kinda thing with a regular part and it worked

#

its just that it doesnt change at all here when i use the same code

scenic turtle
#

the script works with a regular part but not with player characters

viral field
#

yup

#

doesnt throw any errors, just does nothing

scenic turtle
#

do you have any collision groups made?

viral field
#

theres default, studioselectable (i think so at least) and buffer

karmic lindenBOT
#

studio** You are now Level 6! **studio

scenic turtle
#

make sure buffer has the correct settings, set it to not collide with whatever it needs to avoid

viral field
#

already did so

#

if i change the collision group with the part, it changes collisions properly

#

like im able to collide with it when its using default

#

o yeah i forgot to mention

#

but i am testing this with another part to see if i collide with it

#

and its using the buffer collisiongroup

scenic turtle
#

its working right?

viral field
#

not with this, no

scenic turtle
#

you think you can figure it out or nah

viral field
#

idk cuz it would check out in my eyes

#

cuz im accessing the player using the touched event, as well as the character parts

#

so that cant rly be it

#

yeah yknow what im just gonna try a different solution to this

scenic turtle
#

yeah so ive been trying to replicate it and i went with this approach

#

local PhysicsService = game:GetService("PhysicsService")

-- List of body parts you want to affect (works for both R6 and R15)
local allowedParts = {
"Head", "Torso", "Left Arm", "Right Arm", "Left Leg", "Right Leg", -- R6
"UpperTorso", "LowerTorso", "LeftUpperArm", "LeftLowerArm", "LeftHand",
"RightUpperArm", "RightLowerArm", "RightHand",
"LeftUpperLeg", "LeftLowerLeg", "LeftFoot",
"RightUpperLeg", "RightLowerLeg", "RightFoot" -- R15
}

local function isTargetPart(name)
for _, partName in ipairs(allowedParts) do
if name == partName then
return true
end
end
return false
end

script.Parent.Touched:Connect(function(part)
local character = part:FindFirstAncestorOfClass("Model")
if not character then return end

local humanoid = character:FindFirstChildWhichIsA("Humanoid")
if not humanoid then return end

-- Set selected body parts to the "buffer" collision group
for _, child in ipairs(character:GetChildren()) do
    if child:IsA("BasePart") and isTargetPart(child.Name) then
        PhysicsService:SetPartCollisionGroup(child, "buffer")
    end
end

task.wait(1)

-- Reset back to "Default"
for _, child in ipairs(character:GetChildren()) do
    if child:IsA("BasePart") and isTargetPart(child.Name) then
        PhysicsService:SetPartCollisionGroup(child, "Default")
    end
end

end)

#

You can edit the allowedParts list if you want to exclude or include more. this supports both R6 and R15, since it checks names from both rigs. BTW the script only runs when a player touches the object the script is in.