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

Why is this Crouch/Prone Script is not Working Right?

Asked by 9 years ago

Alright, so this a crouch/prone script (more like scripts) I am using for my game. When I tested them out on a different game, they worked fine. I put them in the place where I wanted them to be, and now they won't work correctly. As soon as you go into the crouch/prone position, it will immediately put you back into the normal (standing) position. Output gave me nothing, and I have no idea what the problem is.

Can some please help me? Here's the crouch script:

local StealthLava = script.Parent
local Player = game.Players.LocalPlayer
local Avatar = Player.Character
local Mouse = Player:GetMouse()

-- Emptys
local Hold = nil

--[ Get Items ]--
local Humanoid = Avatar:WaitForChild("Humanoid")
local Torso = Avatar:WaitForChild("Torso")
local RH = Torso:WaitForChild("Right Hip")
local LH = Torso:WaitForChild("Left Hip")

local RL = Avatar:WaitForChild("Right Leg")
local LL = Avatar:WaitForChild("Left Leg")

local RJ = Avatar:WaitForChild("HumanoidRootPart"):WaitForChild("RootJoint")

--[ Functions ]--
function CreateWeld(Part, CF)
    local w = Instance.new("Weld")
    w.Name = "LegWeld"
    w.Parent = Torso
    w.Part0 = Torso
    w.Part1 = Part
    w.C1 = CF
end

function StandUp()
    Humanoid.CameraOffset = Vector3.new(0, 0, 0)
    -- Right Leg
    RH.Part1 = RL

    -- Left Leg
    LH.Part1 = LL

    -- Delete Welds
    for i, s in pairs(Torso:GetChildren()) do
        if (s.Name == "LegWeld") and (s.ClassName == "Weld") then
            s:Destroy()
        end
    end

    -- Raise Character
    RJ.C0 = CFrame.new(0, 0, 0) * CFrame.Angles(0, 0, 0)
    RJ.C1 = CFrame.new(0, 0, 0) * CFrame.Angles(0, 0, 0)
end

--[ Hooks ]--
-- Controls
Mouse.KeyDown:connect(function(Key)
    if (Hold ~= nil) then return end
    if (string.upper(Key) ~= "C") and (string.lower(Key) ~= " ") then return end
    Hold = true

    if (Torso:FindFirstChild("LegWeld") == nil) and (string.lower(Key) ~= " ") then
        -- Right Leg
        RH.Part1 = nil
        CreateWeld(RL, CFrame.new(-0.5, 0.75, 1))

        -- Left Leg
        LH.Part1 = nil
        CreateWeld(LL, CFrame.new(0.5, 0.495, 1.25) * CFrame.Angles(math.rad(90), 0, 0))

        -- Lower Character
        RJ.C0 = CFrame.new(0, -1.25, 0) * CFrame.Angles(0, 0, 0)
        RJ.C1 = CFrame.new(0, 0, 0) * CFrame.Angles(0, 0, 0)

        -- Slow Walk Speed
        Humanoid.CameraOffset = Vector3.new(0, -1.25, 0)
        Humanoid.WalkSpeed = 8

    else
        StandUp()

        -- Normal Walk Speed
        Humanoid.CameraOffset = Vector3.new(0, 0, 0)
        Humanoid.WalkSpeed = 16

    end

    wait(0.5)

    Hold = nil
end)

-- Value Changed
Humanoid.Changed:connect(function()
    if (Humanoid.WalkSpeed > 8) and (Hold == nil) then StandUp() end
end)

Here is the prone script:

local StealthLava = script.Parent
local Player = game.Players.LocalPlayer
local Avatar = Player.Character
local Mouse = Player:GetMouse()

-- Emptys
local Hold = nil

--[ Get Items ]--
local Humanoid = Avatar:WaitForChild("Humanoid")
local Torso = Avatar:WaitForChild("Torso")
local RH = Torso:WaitForChild("Right Hip")
local LH = Torso:WaitForChild("Left Hip")

local RL = Avatar:WaitForChild("Right Leg")
local LL = Avatar:WaitForChild("Left Leg")

local RJ = Avatar:WaitForChild("HumanoidRootPart"):WaitForChild("RootJoint")

--[ Functions ]--
function CreateWeld(Part, CF)
    local w = Instance.new("Weld")
    w.Name = "LegWeld"
    w.Parent = Torso
    w.Part0 = Torso
    w.Part1 = Part
    w.C1 = CF
end

function StandUp()
    Humanoid.CameraOffset = Vector3.new(0, 0, 0)
    -- Right Leg
    RH.Part1 = RL

    -- Left Leg
    LH.Part1 = LL

    -- Delete Welds
    for i, s in pairs(Torso:GetChildren()) do
        if (s.Name == "LegWeld") and (s.ClassName == "Weld") then
            s:Destroy()
        end
    end

    -- Raise Character
    RJ.C0 = CFrame.new(0, 0, 0) * CFrame.Angles(0, 0, 0)
    RJ.C1 = CFrame.new(0, 0, 0) * CFrame.Angles(0, 0, 0)
end

--[ Hooks ]--
-- Controls
Mouse.KeyDown:connect(function(Key)
    if (Hold ~= nil) then return end
    if (string.upper(Key) ~= "X") and (string.lower(Key) ~= " ") then return end
    Hold = true

    if (Torso:FindFirstChild("LegWeld") == nil) and (string.lower(Key) ~= " ") then
        -- Right Leg
        RH.Part1 = nil
        CreateWeld(RL, CFrame.new(-0.4, 1.25, 0.5) * CFrame.fromEulerAnglesXYZ(math.rad(90),-0.25,0))

        -- Left Leg
        LH.Part1 = nil
        CreateWeld(LL, CFrame.new(0.4, 1.25, 0.5) * CFrame.fromEulerAnglesXYZ(math.rad(90),0.25,0))

        -- Lower Character
        RJ.C0 = CFrame.new(0, -2, 0) * CFrame.Angles(0, 0, 0)
        RJ.C1 = CFrame.new(0, 0, 0) * CFrame.Angles(0, 0, 0)

        -- Slow Walk Speed
        Humanoid.CameraOffset = Vector3.new(0, -2, 0)
        Humanoid.WalkSpeed = 4

    else
        StandUp()

        -- Normal Walk Speed
        Humanoid.CameraOffset = Vector3.new(0, 0, 0)
        Humanoid.WalkSpeed = 16

    end

    wait(0.5)

    Hold = nil
end)

-- Value Changed
Humanoid.Changed:connect(function()
    if (Humanoid.WalkSpeed > 8) and (Hold == nil) then StandUp() end
end)

Answer this question