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

[SOLVED] Making a weapon module but the self keyword isn't working?

Asked by 5 years ago
Edited 5 years ago

Basically I'm trying to make a weapon module, but it's not working when I try to use self, meaning everything breaks because I can't get the exact copy of the weapon. Not much more to say, this is my code, any help will be helpful.

function BasicSword:Equip()
    if not self.Owner then print('no owner') return end
    local Character = self.Owner.Character
    if Character then
        print('found owner')
        local CurrentSword = self.Part:Clone()
        CurrentSword.Parent = self.Owner.Character
        local Weld = Instance.new("Weld",CurrentSword)
        Weld.Part0 = CurrentSword
        Weld.Part1 = Character.RightHand
        Weld.C0 = CFrame.new(0,0,2)
        local Humanoid = Character:FindFirstChildOfClass("Humanoid")
        if Humanoid then
            local Animation = Instance.new("Animation")
            Animation.AnimationId = "rbxassetid://66331528"
            Humanoid:LoadAnimation(Animation):Play()
        end
    end
end
0
I literally said "meaning everything breaks because I can't get the exact copy of the weapon" sweettart13947 105 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

Solved it, I thought it was the function, but I was executing the function by doing "PlayerWeapon.Equip()", so self isn't passed in, whereas "PlayerWeapon:Equip()" does pass it in.

Ad

Answer this question