Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

1 comment

0

I literally said "meaning everything breaks because I can't get the exact copy of the weapon"

1 answer

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.