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

How can I change where a weapon is grabbed?

Asked by 8 years ago
Edited 8 years ago

I have a Baseball bat and it keeps on grabbing it from the middle part instead than the down one. Here are both scripts of the Weapon:

Sword Script:

r = game:service("RunService")
local sword = script.Parent.Handle
local Tool = script.Parent

local damage = 5
local p = nil
local humanoid = nil

local slash_damage = 8
local lunge_damage = 12
local regularWalk = 23

local SlashSound = Instance.new("Sound")
SlashSound.SoundId = "http://www.roblox.com/Asset/?ID=12135982"
SlashSound.Parent = sword
SlashSound.Volume = 0.5
SlashSound.Pitch = 0.85

local LungeSound = Instance.new("Sound")
LungeSound.SoundId = "http://www.roblox.com/Asset/?ID=12135982"
LungeSound.Parent = sword
LungeSound.Volume = 0.5
LungeSound.Pitch = 0.85

local UnsheathSound = Instance.new("Sound")
UnsheathSound.SoundId = "http://www.roblox.com/Asset/?ID=12135982"
UnsheathSound.Parent = sword
UnsheathSound.Volume = 0.7
UnsheathSound.Pitch = 0.85

function blow(hit)
    local humanoid = hit.Parent:findFirstChild("Humanoid")
    local vCharacter = Tool.Parent
    local vPlayer = game.Players:playerFromCharacter(vCharacter)
    local hum = vCharacter:findFirstChild("Humanoid") -- non-nil if tool held by a character
    if humanoid~=nil and humanoid ~= hum and hum ~= nil then
        -- final check, make sure sword is in-hand

        local right_arm = vCharacter:FindFirstChild("Right Arm")
        if (right_arm ~= nil) then
            local joint = right_arm:FindFirstChild("RightGrip")
            if (joint ~= nil and (joint.Part0 == sword or joint.Part1 == sword)) then
                tagHumanoid(humanoid, vPlayer)
                humanoid:TakeDamage(damage)
                wait(1)
                untagHumanoid(humanoid)
            end
        end


    end
end


function tagHumanoid(humanoid, player)
    local creator_tag = Instance.new("ObjectValue")
    creator_tag.Value = player
    creator_tag.Name = "creator"
    creator_tag.Parent = humanoid
end

function untagHumanoid(humanoid)
    if humanoid ~= nil then
        local tag = humanoid:findFirstChild("creator")
        if tag ~= nil then
            tag.Parent = nil
        end
    end
end


function attack(humanoid)
    damage = slash_damage
    SlashSound:play()


    local animation = humanoid:LoadAnimation(Tool.twohandedswordhit)
    animation:Play()
    animation.KeyframeReached:connect(function(string)
        if string == "throwdown" then
            animation:Stop()
            animation:remove()
        end
    end)
end

function lunge(humanoid)
    damage = lunge_damage
    LungeSound:play()

    local anim = humanoid:LoadAnimation(Tool.bigtwohandhit)
    anim:Play(0.1,1,4)
    anim.KeyframeReached:connect(function(string)
        if string == "throwdown" then
            anim:Stop()
            anim:remove()
        end
    end)

    damage = slash_damage
end

function swordUp()
    Tool.GripForward = Vector3.new(-1,0,0)
    Tool.GripRight = Vector3.new(0,1,0)
    Tool.GripUp = Vector3.new(0,0,1)
end

function swordOut()
    Tool.GripForward = Vector3.new(0,0,1)
    Tool.GripRight = Vector3.new(0,1,0)
    Tool.GripUp = Vector3.new(1,0,0)
end

function swordAcross()
    -- parry
end


Tool.Enabled = true
local last_attack = 0
function onActivated()

    if not Tool.Enabled then
        return
    end

    Tool.Enabled = false

    local character = Tool.Parent;
    local humanoid = character.Humanoid
    if humanoid == nil then
        print("Humanoid not found")
        return 
    end

    t = r.Stepped:wait()

    if (t - last_attack < .2) then
        lunge(humanoid)
    else
        attack(humanoid)
    end

    last_attack = t

    Tool.Enabled = true
end

function onEquipped()

    UnsheathSound:play()
    local humanoid = Tool.Parent:FindFirstChild("Humanoid",false)
    animation = humanoid:loadAnimation(Tool.twohandedswordhit)
    p = game.Players:GetPlayerFromCharacter(Tool.Parent)

end

script.Parent.Activated:connect(onActivated)
script.Parent.Equipped:connect(onEquipped)

connection = sword.Touched:connect(blow)


Local Gui

%VywwpqLBRvghzLEWlmj01Hrxowc/Ki8uwzTuEL1U4VXXGsjT8/n5thDtEpZsLu1caD6T37n0EMq37y5QN29wu12b4jUvd8sfvCD+pc7nVzsoHJzj67CD/PBYKNixnEtOx/dqzaoUuAEjAwp9dPA+RAmKq/HZGaP35CZC7Spd1gg=476%local Tool = script.Parent;

enabled = true
function onButton1Down(mouse)
    if not enabled then
        return
    end

    enabled = false
    mouse.Icon = "http://www.roblox.com/asset/?id=45313269"

    wait(.5)
    mouse.Icon = "http://www.roblox.com/asset/?id=45313269"
    enabled = true

end

function onEquippedLocal(mouse)

    if mouse == nil then
        print("Mouse not found")
        return 
    end

    mouse.Icon = "rbxasset://textures\\GunCursor.png"
    mouse.Button1Down:connect(function() onButton1Down(mouse) end)
end


Tool.Equipped:connect(onEquippedLocal)

And here a link of how is the bat being grabbed:

http://imgur.com/a/cYLBO

0
Thanks :D MrCarri 4 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

Answered

0
Can you edit the title with [Answered] User#5423 17 — 8y
Ad

Answer this question