I am making a game with a gun shop and the guns have a script in them that makes you hold the gun how I want them to. Yet its not an animation. But whenever I replicate it the script stops working? Can someone please help me. This is the script:
selected = false
RSH, LSH = nil, nil
GRP = nil
RW, LW = Instance.new("Weld"), Instance.new("Weld")
anim = "none"
function WaitForChild(obj, ch_n)
local t = time()
while not obj:FindFirstChild(ch_n) and time() - t < 10 do wait(0.1) end
return obj:FindFirstChild(ch_n)
end
script.Parent.Equipped:connect(function()
if script.Parent.Parent:FindFirstChild("Humanoid") then
if selected then return end
selected = true
player = game.Players:playerFromCharacter(script.Parent.Parent)
local ch = script.Parent.Parent
WaitForChild(ch, "Torso")
RSH = WaitForChild(ch.Torso, "Right Shoulder")
LSH = WaitForChild(ch.Torso, "Left Shoulder")
GRP = WaitForChild(ch["Right Arm"], "RightGrip")
_G.Grip = GRP
--
RSH.Part1 = nil
LSH.Part1 = nil
--
RW.Part0 = ch.Torso
RW.C0 = CFrame.new(1.5, 0.5, 0) --* CFrame.fromEulerAnglesXYZ(1.3, 0, -0.5)
RW.C1 = CFrame.new(0, 0.5, 0)
RW.Part1 = ch["Right Arm"]
RW.Parent = ch.Torso
_G.R = RW
--
LW.Part0 = ch.Torso
LW.C0 = CFrame.new(-1.5, 0.5, 0) --* CFrame.fromEulerAnglesXYZ(1.7, 0, 0.8)
LW.C1 = CFrame.new(0, 0.5, 0)
LW.Part1 = ch["Left Arm"]
LW.Parent = ch.Torso
_G.L = LW
--
GRP.C0 = CFrame.new(0, -1, -0.5) * CFrame.fromEulerAnglesXYZ(-1.22, -0.45, 0.22)
for i = 0, 1, 0.05 do
wait()
RW.C0 = CFrame.new(1.5, 0.5, 0.25) * CFrame.fromEulerAnglesXYZ(1.3*i, 0, -0.5*i)
LW.C0 = CFrame.new(-1.5, 0.5, 0) * CFrame.fromEulerAnglesXYZ(1.7*i, 0, 0.8*i)
LW.C1 = CFrame.new(0.3*i, 1+1*i, 0)
end
wait()
local rg = (ch["Right Arm"]:FindFirstChild("RightGrip") or GRP)
if rg ~= GRP then
GRP.Parent = ch["Right Arm"]
rg:remove()
end
end
end)
script.Parent.Unequipped:connect(function()
selected = false
local pl = player
RW.C0 = CFrame.new(0,0,0) * CFrame.fromEulerAnglesXYZ(0,0,0)
LW.C0 = CFrame.new(0,0,0) * CFrame.fromEulerAnglesXYZ(0,0,0)
LW.C1 = CFrame.new(0,0,0)
RW.Parent = nil
LW.Parent = nil
RSH.Part1 = pl.Character["Right Arm"]
LSH.Part1 = pl.Character["Left Arm"]
end)
function armReload()
for i = 0, 1, 0.1 do
wait()
LW.C0 = CFrame.new(-1.5, 0.5, 0) * CFrame.fromEulerAnglesXYZ(1.3*i, 0, 0.9*i)
LW.C1 = CFrame.new(0.3*i, 1+1*i, 0)
end
end
function gunOut()
for i = 0, 0.3, 0.06 do
wait()
GRP.C0 = CFrame.new(0+i, -1-i, 0+(2*i)) * CFrame.fromEulerAnglesXYZ(-2.22, -0.45, 0.42)
LW.C0 = CFrame.new(-1, 0.5, 0) * CFrame.fromEulerAnglesXYZ(4.2, 0, 2.9)
LW.C1 = CFrame.new(0.8*i, 1.1+i, -0.3)
end
end
function gunReturn()
RW.C0 = CFrame.new(1.5, 0.5, 0.25) * CFrame.fromEulerAnglesXYZ(1.3, 0, -0.5)
LW.C0 = CFrame.new(-1.5, 0.5, 0) * CFrame.fromEulerAnglesXYZ(1.7, 0, 0.8)
LW.C1 = CFrame.new(0.3, 1+1, 0)
GRP.C0 = CFrame.new(0, -1, -0.5) * CFrame.fromEulerAnglesXYZ(-1.22, -0.45, 0.22)
end

7 comments
I think keep the scripts as the child of your script and place them in after its done? Just maybe
ok
it didn't work sorry but thanks for trying to help :D
You can try disabling the script inside the tool and reenabling it.
already tried that but thanks for anwsering
I've already come across this problem before in the past. Can you confirm that there aren't any errors in the output?
yeah there arent any