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

How to fix revolver reload on murder mystery?

Asked by 2 years ago

Hello, another question to ask about the game I am making, whenever I shoot the gun goes off, it is effective, and it plays the reloading sound clip, but it reloads I have to unequip and re- the gun to shoot again. It doesn't fully reload. Help, please.

-- Basic settings
local REVOLVER_SHOOT_COOLDOWN = 3
local XP_PER_KILL = script.Parent.KillXP.Value 

local tool = script.Parent
local debounce = false
local shootCooldown = false

local toolPlr
local animShoot
local touchEvent

script.ClientLeftDown.OnServerEvent:connect(function(plr, mouseHitPos, hitPart)

    -- Make sure correct player
    if plr ~= toolPlr then
        return
    end

    -- See if should
    if not debounce and not shootCooldown and tool.Parent ~= nil and tool.Parent.ClassName ~= "Backpack" and tool.Parent:FindFirstChild("Head") then
        debounce = true

        -- Check to make sure there is actually a hitpart
        if hitPart ~= nil then

            -- Ray cast to check if the hit part is valid
            local ray = Ray.new(tool.Parent.Head.Position, (hitPart.Position - tool.Parent.Head.Position).Unit * 2500)
            local ignore = game.ServerScriptService.Functions.GetRayIgnoreList:Invoke()
            table.insert(ignore, tool.Parent)
            local hit, hitPos, normal = workspace:FindPartOnRayWithIgnoreList(ray, ignore, false, true)

            -- Activate cooldown
            shootCooldown = true
            spawn(function()
                wait(REVOLVER_SHOOT_COOLDOWN)
                shootCooldown = false
            end)

            -- Check if player
            if hit ~= nil and hit.Parent ~= nil then
                if hit.Parent:FindFirstChild("Humanoid") then
                    local chr = hit.Parent

                    -- Check if not on same team
                    local okay = true
                    local otherPlr = game.Players:GetPlayerFromCharacter(chr)
                    if chr:FindFirstChild("Knife") then
                        if chr.Knife.TeamColor.Value == tool.TeamColor.Value then
                            okay = false
                        end
                    end
                    if chr:FindFirstChild("Revolver") then
                        if chr.Revolver.TeamColor.Value == tool.TeamColor.Value then
                            okay = false
                        end
                    end
                    if otherPlr.Backpack:FindFirstChild("Knife") then
                        if otherPlr.Backpack.Knife.TeamColor.Value == tool.TeamColor.Value then
                            okay = false
                        end
                    end
                    if otherPlr.Backpack:FindFirstChild("Revolver") then
                        if otherPlr.Backpack.Revolver.TeamColor.Value == tool.TeamColor.Value then
                            okay = false
                        end
                    end

                    -- Kill if not
                    if okay and chr:FindFirstChild("IsThick") == nil then

                        -- Find if the other is a murderer
                        local isMurderer = true
                        if chr:FindFirstChild("Knife") == nil and game.Players:GetPlayerFromCharacter(chr).Backpack:FindFirstChild("Knife") == nil then
                            isMurderer = false
                        end

                        -- Damage the person who was shot
                        chr.Humanoid.Health = chr.Humanoid.Health - 100.0001

                        -- Check if dead
                        if chr.Humanoid.Health <= 0 then

                            -- Kill and make ragdoll
                            local otherChrTorsoPos = chr.Torso.Position
                            game.ServerScriptService.Functions.GameDeath:Fire(chr, (otherChrTorsoPos - tool.Parent.Torso.Position).Unit)

                            -- Give player one kill
                            local plr = game.Players:GetPlayerFromCharacter(tool.Parent)
                            plr.Achievements.RevolverKills.Value = plr.Achievements.RevolverKills.Value + 1

                            -- Kill self if not murderer
                            if not isMurderer and tool.OnlyKillMurderer.Value then
                                tool.Parent.Humanoid.Health = 0
                                game.ServerScriptService.Functions.GameDeath:Fire(tool.Parent, (tool.Parent.Torso.Position - otherChrTorsoPos).Unit)
                            elseif XP_PER_KILL > 0 then
                                game.ServerScriptService.Functions.GiveXP:Fire(plr, XP_PER_KILL, 0)
                                game.ReplicatedStorage.Interactions.Client.RunKillFlash:FireClient(toolPlr)
                            else
                                game.ReplicatedStorage.Interactions.Client.RunKillFlash:FireClient(toolPlr)
                            end

                        end

                    elseif chr:FindFirstChild("IsThick") ~= nil then

                        -- Remove shield
                        chr.IsThick:destroy()

                    end

                else

                    -- Redo ray cast
                    local ray = Ray.new(tool.Parent.Head.Position, (mouseHitPos - tool.Parent.Head.Position).Unit * 2500)
                    local hit, hitPos, normal = workspace:FindPartOnRayWithIgnoreList(ray, ignore, false, true)

                    -- Check if valid
                    if hit ~= nil and hit.Parent ~= nil and hit.CanCollide == true and hit.Transparency ~= 1 and hit.Parent.Name ~= "Ragdoll"  then

                        -- Make bullet hole
                        local part = Instance.new("Part")
                        part.Name = "BulletHole"
                        part.Transparency = 1
                        part.CFrame = CFrame.new(hitPos, hitPos + normal)
                        part.Anchored = true
                        part.CanCollide = false
                        part.Size = Vector3.new(0.1, 0.1, 0.1)
                        part.TopSurface = Enum.SurfaceType.Smooth
                        part.BottomSurface = Enum.SurfaceType.Smooth
                        local decal = Instance.new("Decal", part)
                        decal.Texture = "rbxassetid://46648463"
                        decal.Face = Enum.NormalId.Front
                        local smoke = script.BulletSmoke:clone()
                        smoke.Color = ColorSequence.new(hit.Color)
                        smoke.Parent = part
                        part.Parent = workspace
                        smoke:Emit(50)

                    end

                end

            end

        end

        -- Play the shoot animation
        if tool:FindFirstChild("Handle") ~= nil and tool.Parent ~= nil and tool.Parent.ClassName ~= "Backpack" then
            animShoot:Play()
            game.ReplicatedStorage.Interactions.Client.PlaySound:FireAllClients(tool.Handle.Shoot)
            tool.EmitterPart.ShootFire:Emit(10)
            tool.EmitterPart.ShootSmoke:Emit(25)
            wait(0.5)
            game.ReplicatedStorage.Interactions.Client.PlaySound:FireAllClients(tool.Handle.Reload)

        end

    end

end)

tool.Equipped:connect(function()

    -- Weld the emitter part
    if tool.Handle:FindFirstChild("EmitterWeld") then
        tool.Handle.EmitterWeld:destroy()
    end
    local weld = Instance.new("Weld")
    weld.Name = "EmitterWeld"
    weld.Part0 = tool.Handle
    weld.Part1 = tool.EmitterPart
    weld.C0 = script.Parent.Grip - script.Parent.GripPos
    weld.C1 = CFrame.new(tool.EmitterOffset.Value)
    weld.Parent = tool.Handle

    -- Set player
    toolPlr = game.Players:GetPlayerFromCharacter(tool.Parent)

    -- Load anim stab
    animShoot = tool.Parent.Humanoid:LoadAnimation(script.RevolverShoot)
    animShoot.Stopped:connect(function()
        debounce = false
    end)

    -- Play draw sound
    game.ReplicatedStorage.Interactions.Client.PlaySound:FireAllClients(tool.Handle.Draw)

    -- Make display revolver invisible
    if tool.Parent:FindFirstChild("DisplayRevolver") then
        tool.Parent.DisplayRevolver.Transparency = 1
        for _, i in pairs(tool.Parent.DisplayRevolver:GetChildren()) do
            if i.ClassName ~= "SpecialMesh" and i.ClassName ~= "Weld" then
                i.Enabled = false
            end
        end
    end

    -- Disable for a 'lil bit the revolver
    debounce = true
    wait(0.25)
    debounce = false

end)

tool.Unequipped:connect(function()

    -- Destroy animation tracks
    animShoot:Stop()
    animShoot:destroy()

    -- Make display revolver visible
    local chr = tool.Parent
    if tool.Parent ~= nil and tool.Parent.ClassName == "Backpack" then
        chr = tool.Parent.Parent.Character
    end
    if chr ~= nil then
        if chr:FindFirstChild("DisplayRevolver") then
            chr.DisplayRevolver.Transparency = 0
            for _, i in pairs(chr.DisplayRevolver:GetChildren()) do
                if i.ClassName ~= "SpecialMesh" and i.ClassName ~= "Weld" then
                    i.Enabled = true
                end
            end
        end
    end

end)

1 answer

Log in to vote
0
Answered by 2 years ago

Turns out it was an animation issue!

Ad

Answer this question