✓ Accepted answer
SOLUTION 1: CHECKING PARTS
You're trying to check if the character is R6 or R15, so you should be checking if the character has a part called "LowerTorso" or not. However, your script appears to instead check if the character exists:
local char = otherPart.Parent
if char then
Note: this will always be true, because you're checking if otherPart's parent isn't nil, in a function that is triggered by otherPart touching part - and a part with a nil parent can't touch anything, so the event would not be triggered.
Here's how you can check which torso exists inside the character:
local torso1 = char:FindFirstChild("Torso")
local torso2 = char:FindFirstChild("LowerTorso")
if torso1 then
elseif torso2 then
end
A few suggestions:
when referring to a child, use :WaitForChild, so you can avoid errors if the child hasn't loaded yet.
:connect is deprecated - use :Connect.
I noticed you didn't use the i variable in your for loop. In such cases, it is recommended to use _ - basically the trash can variable.
you can declare the function inside the :Connect
Here's the fixed code:
local part = script.Parent
local box = part.Parent:WaitForChild("Box1")
local board = part.Parent:WaitForChild("Board")
local settings = part.Parent:WaitForChild("Settings")
part.Touched:Connect(function(otherPart)
local char = otherPart.Parent
local torso1 = char:FindFirstChild("Torso")
local torso2 = char:FindFirstChild("LowerTorso")
if torso1 then
torso1.Anchored = true
elseif torso2 then
torso2.Anchored = true
end
char.Name = settings.PlayerNames
for _,v in pairs(box:GetChildren()) do
v.CanCollide = false
end
end)
SOLUTION 2: RIGTYPE
Very similiar. Here you check if the humanoid exists, and then its RigType.
local part = script.Parent
local box = part.Parent:WaitForChild("Box1")
local board = part.Parent:WaitForChild("Board")
local settings = part.Parent:WaitForChild("Settings")
part.Touched:Connect(function(otherPart)
local char = otherPart.Parent
local humanoid = char:FindFirstChildOfClass("Humanoid")
if humanoid then
if humanoid.RigType == Enum.HumanoidRigType.R6 then
humanoid:WaitForChild("Torso").Anchored = true
elseif humanoid.RigType == Enum.HumanoidRigType.R15 then
humanoid:WaitForChild("LowerTorso").Anchored = true
end
end
char.Name = settings.PlayerNames
for _,v in pairs(box:GetChildren()) do
v.CanCollide = false
end
end)
2 comments
fix indentation pls
fixed