Hi everyone! Its my first time making a game and i got this error. i dont know whats wrong. please help me!

The script is here:

local function equipPet(player,pet)
	
	local character = player.Character
	
	if pet ~= nil and character ~= nil then
		
		if character:FindFirstChild(player.Name.."Pet") then 
			character[player.Name.."Pet"]:Destroy() 
		end
		if character.HumanoidRootPart:FindFirstChild("attachmentCharacter") then 
			character.HumanoidRootPart:FindFirstChild("attachmentCharacter"):Destroy() 
		end
			
		pet.Name = "Pet"
		
		pet:SetPrimaryPartCFrame(character.HumanoidRootPart.CFrame)
		
		local modelSize = pet.PrimaryPart.Size
		
		local attachmentCharacter = Instance.new("Attachment")
		attachmentCharacter.Visible = false
		attachmentCharacter.Name = "attachmentCharacter"
		attachmentCharacter.Parent = character.HumanoidRootPart
		attachmentCharacter.Position = Vector3.new(1,1,0)+modelSize
		
		local attachmentPet = Instance.new("Attachment")
		attachmentPet.Visible = false
		attachmentPet.Parent = pet.PrimaryPart
		
		local allignPosition = Instance.new("AlignPosition")
		allignPosition.MaxForce = 25000
		allignPosition.Attachment0 = attachmentPet
		allignPosition.Attachment1 = attachmentCharacter
		allignPosition.Responsiveness = 25
		allignPosition.Parent = pet

		local allignOrientation = Instance.new("AlignOrientation")
		allignOrientation.MaxTorque = 25000
		allignOrientation.Attachment0 = attachmentPet
		allignOrientation.Attachment1 = attachmentCharacter
		allignOrientation.Responsiveness = 25
		allignOrientation.Parent = pet
		pet.Parent = character
	end
	
end

game.Players.PlayerAdded:Connect(function(player)
	local stats = Instance.new("Folder")
	stats.Name = "leaderstats"
	stats.Parent = player
	
	local strength = Instance.new("IntValue")
	strength.Name = "Strength"
	strength.Value = 0
	strength.Parent = stats
	
	local exp = Instance.new("IntValue")
	exp.Name = "EXP"
	exp.Value = 0
	exp.Parent = stats
	
	local money = Instance.new("IntValue")
	money.Name = "Money"
	money.Value = 0
	money.Parent = stats
	
	local inventory = Instance.new("Folder")
	inventory.Name = "PetInventory"
	inventory.Parent = player
	
	local equippedPet = Instance.new("StringValue")
	equippedPet.Parent = player
	equippedPet.Name = "EquippedPet"
	
	player.CharacterAdded:Connect(function(char)
		if game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value) then
			equipPet(player,game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value):Clone())
		end
	end)
	
	local doublestrength = Instance.new("BoolValue")
	doublestrength.Name = "DoubleStrength"
	doublestrength.Value = false
	doublestrength.Parent = player
	
	equippedPet.Changed:Connect(function()
		if equippedPet.Value ~= nil then
			if game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value) then
				equipPet(player,player,game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value):Clone())
			end
		end
	end)
	
end)
game.ReplicatedStorage.EquipPet.OnServerEvent:Connect(function(player,petName)
	local pet = game.ReplicatedStorage.Pets:FindFirstChild(petName)
	if pet and player.PetInventory:FindFirstChild(petName) then
		player.EquippedPet.Value = petName
	end
end)

game.ReplicatedStorage.UnequipPet.OnServerEvent:Connect(function(player)
	player.EquippedPet = ""
	if player.Character:FindFirstChild(player.Name.."Pet") then
		player.Character[player.Name.."Pet"]:Destroy()
	end
	if player.Character.HumanoidRootPart:FindFirstChild("attachmentCharacter") then
		player.Character.HumanoidRootPart:FindFirstChild("attachmentCharacter"):Destroy()
	end
	end)


1 comment

0

Line #?