Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Weld Gun Script Breaks/Works half the time?

Asked by 7 years ago

So here is my whole script! Question is below

local Player = game:GetService("Players")
script.Parent.Equipped:connect(function(gun)

local Handle = script.Parent.Handle
local Union = script.Parent.Union
local Shoot = script.Parent.Shoot
local Hand = Player.LocalPlayer.Character

Handle.Anchored = false
Union.Anchored = false
Shoot.Anchored = false
    wait()
    local weld = Instance.new ("Weld", Handle)
    weld.Part0 = Handle
    weld.Part1 = Union
    weld.C1 = CFrame.Angles(0,0,0) * CFrame.new(0,1,0)
    local weld2 = Instance.new ("Weld", Hand)
    weld2.Part0 = game.Players.LocalPlayer.Character["Right Arm"]
    weld2.Part1 = Handle
    weld2.C1 = CFrame.Angles(math.rad(120), math.rad(30),0) * CFrame.new(1,0.4,0)
    local weld3 = Instance.new ("Weld", Union)
    weld3.Part0 = Union
    weld3.Part1 = Shoot
    weld3.C1 = CFrame.Angles(0,0,0) * CFrame.new(0,0,0)

end)

function KeyPressed(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.One then 

local Handle = script.Parent.Handle
local Union = script.Parent.Union
local Shoot = script.Parent.Shoot
local Hand = Player.LocalPlayer.Character

Handle.Anchored = false
Union.Anchored = false
Shoot.Anchored = false

    wait()
    local weld = Instance.new ("Weld", Handle)
    weld.Part0 = Handle
    weld.Part1 = Union
    weld.C1 = CFrame.Angles(0,0,0) * CFrame.new(0,1,0)
    local weld2 = Instance.new ("Weld", Hand)
    weld2.Part0 = game.Players.LocalPlayer.Character["Right Arm"]
    weld2.Part1 = Handle
    weld2.C1 = CFrame.Angles(math.rad(120), math.rad(30),0) * CFrame.new(1,0.4,0)
    local weld3 = Instance.new ("Weld", Union)
    weld3.Part0 = Union
    weld3.Part1 = Shoot
    weld3.C1 = CFrame.Angles(0,0,0) * CFrame.new(0,0,0)
    end
end
game:GetService("UserInputService").InputBegan:connect(KeyPressed)

So, what happens is that it sometimes goes in the direction where its suppose to be. But other times it just gives up and stays in a "Default" position. There are NO output errors, and I'm about to bust my monitor. Thanks!

0
You should try using the built in Motor6D's, they work just as good! :) xuefei123 214 — 7y

Answer this question