Hello, I’m not in Studio and have no access to it at the moment, yet I decided to write a Pick-up Script to Grab a Rifle laying on the Ground, then place it on your Back, I would just like someone to let me know if there’s any potential issues, as well as helping me set the CFrames for the placement on the Back and Orientation

local Rifle = workspace:WaitForChild(“Rifle”)
local ClickDetector = Rifle:FindFirstChild(“ClickDetector”)
ClickDetector.MouseClick:Connect(function(Player)
   if (Player) then
      local Character = Player.Character or Player.CharacterAdded:wait()
      if (Character and Rifle) then
         local Torso = Character:FindFirstChild(“Torso”)
         if (Character and Rifle and Torso) then
            local Weld = Instance.new(“Weld”)
            Rifle.CFrame = Torso.CFrame * CFrame.new(Back Vector) * CFrame.Angles(Orientation Vector)
            Weld.Part0 = Torso
            Weld.C0 = Torso.CFrame:Inverse()
            Weld.Part1 = Rifle
            Weld.C1 = Rifle.CFrame:Inverse()
            Weld.Parent = Rifle
         end
      end
   end
end)

Thanks!

5 comments

0

you dont need to check if rifle exists, because the script will yield if it doesnt. and you definitely dont need to check for it and character twice

0

character follows the same logic as rifle btw

0

I heard that’s the best method to Index the Character, as it’s secondary precaution reinforces the Index making sure you get the Character, as obviously that’s Important. I also check to make sure the Rifle didn’t disappear on me, as that would break the Weld, unless I should wrap it in a pcall?

0

No. The rifle should not disappear on you

0

Hey, you never know it “should not”, doesn’t mean it can’t