Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Tryed making my game r6 and r15 compattiable but it won't get past the if statements?

So im trying to make my game r6 and r15 compattiable but i think i did something wrong with the if statements how do i fix this there is no error in the output


game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(character)
		if character.Humanoid.RigType == "R15" then
			character.LeftFoot.Locked = true

		character.LeftHand.Locked = true
		character.LeftLowerArm.Locked = true
		character.LeftLowerLeg.Locked = true
		character.LeftUpperArm.Locked = true
		character.LeftUpperLeg.Locked = true
		character.LowerTorso.Locked = true
		character.RightFoot.Locked = true
		character.RightHand.Locked = true
		character.RightLowerArm.Locked = true
		character.RightLowerLeg.Locked = true
		character.RightUpperArm.Locked = true
		character.RightUpperLeg.Locked = true
		character.UpperTorso.Locked = true
		character.Head.Locked = true
		character.HumanoidRootPart.Locked = true
		elseif character.Humanoid.RigType == "R6" then
			character.Head.Locked = true
			character.HumanoidRootPart.Locked = true
			character.Torso.Locked = true
			character["Left Arm"].Locked = true
			character["Left Leg"].Locked = true
			character["Right Arm"].Locked = true
			character["Right Leg"].Locked = true
			
		end
	
		
	end)
end)

2 comments

0

I see the issue here. Your indenting is horrible.

0

when in doubt, print() it out

2 answers

✓ Accepted answer

Simple fix , use Enum.HumanoidRigType instead of "R15" or "R6". Script:

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(character)
       if character.Humanoid.RigType == Enum.HumanoidRigType.R15 then
        character.LeftFoot.Locked = true
        character.LeftHand.Locked = true
        character.LeftLowerArm.Locked = true
        character.LeftLowerLeg.Locked = true
        character.LeftUpperArm.Locked = true
        character.LeftUpperLeg.Locked = true
        character.LowerTorso.Locked = true
        character.RightFoot.Locked = true
        character.RightHand.Locked = true
        character.RightLowerArm.Locked = true
        character.RightLowerLeg.Locked = true
        character.RightUpperArm.Locked = true
        character.RightUpperLeg.Locked = true
	    character.UpperTorso.Locked = true
        character.Head.Locked = true
        character.HumanoidRootPart.Locked = true
        elseif character.Humanoid.RigType == Enum.HumanoidRigType.R6 then
            character.Head.Locked = true
            character.HumanoidRootPart.Locked = true
            character.Torso.Locked = true
            character["Left Arm"].Locked = true
            character["Left Leg"].Locked = true
            character["Right Arm"].Locked = true
            character["Right Leg"].Locked = true
        end
    end)
end)

3 comments

0

This answer isn't good. It's just "do this." But why? "because I say so", and you should also use loops

0

I see Thanks

0

XxGamer, I've showed you how to clean up your code, it's best if you use that method

You could make your code a lot cleaner by doing this

game.Players.PlayerAdded:Connect(function(Player) --// Players entered Game, cought their index
   
   local Character = workspace:WaitForChild(Player.Name) --// Gets Character
  
   if (Character.Humanoid.RigType == Enum.HumanoidRigType.R15) then --// Check RigType
      
      local BodyParts = {}; --// Table of their body parts
      for _,BodyPart in pairs(Character:GetChildren()) do --// Gets body parts
         if BodyPart:IsA("BasePart") then
            table.insert(BodyParts, BodyPart)
         end
      end

      for i = 1,#BodyParts do
         BodyParts[i].Locked = true --// Locks them all
      end

   elseif (Character.Humanoid.RigType == Enum.HumanoidRigType.R6) then

      local BodyParts = {};
      for _,BodyPart in pairs(Character:GetChildren()) do
         if BodyPart:IsA("BasePart") then
            table.insert(BodyParts, BodyPart)
         end
      end

      for i = 1,#BodyParts do
         BodyParts[i].Locked = true
      end

   end

end)

Hope this works

1 comment

0

It's a lot more efficient, the more efficient the less probability of your Script breaking, for instance using Enum, and wrapping loops

This discussion is preserved as it was. New answers, comments, and votes are closed.