I am working on an fps engine for my game. I want to make the gun weld to the fps arms but this happens.
I assume I have to do something with CFrame:ToObjectSpace() but i am not sure because I’ve tried a few things with it.
When I create the weld I want to offset it by 1 stud in the direction of the players hands. But that offset is different with the camera direction or where the fps arms are facing.
Here is the code for welding,
EquipDebounce=true
local Model = Models.Client:Clone()
ContentProvider:PreloadAsync({Model})
local Conf = require(tool.Config)
local Handle = Model:WaitForChild("Handle")
local RightGrip = RightArm:WaitForChild("RightGrip")
-- Below I think is the problem.
Handle.CFrame = (RightArm.CFrame-RightArm.CFrame.upVector*1)*CFrame.Angles(rad(-90),0,0) -- Offset
RightGrip.Part0 = RightArm
RightGrip.Part1 = Handle
RightGrip.C0 = RightArm.CFrame:Inverse()
RightGrip.C1 = Handle.CFrame:Inverse()
Model.Parent = Dummy
EquipDebounce=true
local AlreadyWelded = false
local Model = Models.Client:Clone()
ContentProvider:PreloadAsync({Model})
local Conf = require(tool.Config)
local Handle = Model:WaitForChild("Handle")
local RightGrip = RightArm:WaitForChild("RightGrip")
-- Below I think is the problem.
if not AlreadyWelded then
Handle.CFrame = (RightArm.CFrame-RightArm.CFrame.upVector*1)*CFrame.Angles(rad(-90),0,0) -- Offset
AlreadyWelded = true
end
RightGrip.Part0 = RightArm
RightGrip.Part1 = Handle
RightGrip.C0 = RightArm.CFrame:Inverse()
RightGrip.C1 = Handle.CFrame:Inverse()
Model.Parent = Dummy
At first glance no because I have a script that just deletes the weld when unequipped.
It would do the same thing because it uses this:
which is the problem
code for deleting weld:
Character.ChildRemoved:Connect(function(child)
EquipDebounce=true
if child:IsA("Tool") and child.Name==Equipped then
Equipped=nil
Dummy.Client:Destroy()
ToolInfo.VPModel:Destroy()
stopAllAnimations()
end
EquipDebounce=false
end)